我正在尝试解决一个问题,这是否可行或不尝试与该论坛中的专家一起了解,问题在于使用 java 进行线程间通信。
我有一堂课:
class A {
public void setX() {}
public void setY() {}
}
我有 4 个或更多线程,例如:
T1,T2,T3,T4 are the threads that operates on this Class
如果线程正在设置一种方法,所有其他线程都将在其他方法上操作,我必须以这种方式设计同步
例如:
if thread T1 is operating on setX() methods then T2,T3,T4 can work on setY()
if thread T2 is operating on setX() methods then T1,T3,T4 can work on setY()
if thread T3 is operating on setX() methods then T1,T2,T4 can work on setY()
if thread T4 is operating on setX() methods then T1,T2,T3 can work on setY()