我有一个旧代码,如下所示。在某些时候,我希望这个代码在两个线程中运行。但我对现有代码的修改权限受到限制。因为代码中的业务逻辑非常复杂。所以我不想把方法分成两个或更多。以下是示例代码?
public void task1(){
logger.debug(thisThreadName+"Issue 1");
logger.debug(thisThreadName+"Issue 2");
logger.debug(thisThreadName+"Validate 1");
logger.debug(thisThreadName+"Issue 3");
logger.debug(thisThreadName+"Validate 2");
}
我想要的是:
1) Domain Thread shoud write Issue1, Issue2
2) The Domain Thread should create a new one
3) The Domain Thread should start to wait.
4) The New thread should run till the end of method
5) The New Thread should write Validate 1, Issu3, Validate 2
6) The New Thread should set controlVariable( true or false)
7) The New Thread should be finish and destroyed.
8) The Domain Thread should control controlVariable. If it is true. It should jump to the end of method. If it is false. It should rewrite Issue1 and Issue2
Sample Output Is:
DomainThread Issue 1
DomainThread Issue 2
NewThread Validate 1
NewThread Issue 3
NewThread Validate 2
是否有针对此要求的解决方案?
按方式:我可能不会更改方法签名和方法实现块。我可能只是在方法中添加额外的代码行。
我想要实现的是:在运行验证之前,主线程应该知道是否验证了Validation1和Validation2。