Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在评估正则表达式时消除线程阻塞-灾难性回溯_Java_Regex_Multithreading - Fatal编程技术网

Java 如何在评估正则表达式时消除线程阻塞-灾难性回溯

Java 如何在评估正则表达式时消除线程阻塞-灾难性回溯,java,regex,multithreading,Java,Regex,Multithreading,如何杀死一个正在计算正则表达式的线程,--这会发生灾难性的回溯 有没有一种方法不使用Thread.stop(),而是杀死线程 我已经尝试了future.cancel(true),但这不会终止线程,只是尝试中断线程 鉴于这是一个类: public class myRegex implements Runnable { public void run(){ this.evaluateRegex(pattern, matcher); // internally calls the patte

如何杀死一个正在计算正则表达式的线程,--这会发生灾难性的回溯

有没有一种方法不使用Thread.stop(),而是杀死线程

我已经尝试了future.cancel(true),但这不会终止线程,只是尝试中断线程

鉴于这是一个类:

public class myRegex implements Runnable
{
   public void run(){

this.evaluateRegex(pattern, matcher);  // internally calls the patterns and matcher...
}

    public void evaluateRegex(Stirng pattern, String matcher)
{
// does the code specific logic
}

}
如何终止具有回溯功能的长线程

如何终止具有回溯功能的长线程

每一次回溯都有一个条件需要评估以返回或调用下一级

if(conditionToReturn){
   return;
}
else{
    result = callRecursiveBacktrack();

}
应该有一个丑陋的实例变量
canRun
(是否同步取决于具体情况)来打破您的设计模式 大概是这样的:

if (this.canRun) {
    if (conditionToReturn) {
        return;
    } else {
        result = callRecursiveBacktrack();
        if (!this.canRun) {
            return;
        }
    } 
  else {
        return;
   }

我不认为,您将能够在运行时检测回溯。。。您的正则表达式可能有问题…您可以共享您的正则表达式吗?为什么不使用内置的中断机制
this.canRun
=>
Thread.interrupted()
@assylias是预引用的问题:1更多的布尔变量声明和直接访问或函数调用,而不是那么重要的imho。所需的逻辑将起作用。他必须为特定的正则表达式使用模式匹配器。该逻辑是API内部的。我认为他无法改变这一点。@Dhrubajyoti每个函数都可以是递归的,也就是说其他的东西是正确的或nt。问题是如何停止递归(回溯)@matheszabi,如果您使用的是3,这并不特别容易。参与方正则表达式库,或仅来自标准类库的正则表达式库。你不想重写并完全拥有它。