开发者

Thread BLOCK issue in java

开发者 https://www.devze.com 2023-02-13 10:16 出处:网络
I have thread BLOCK issue. Please help me. In my class, i have two objects. One is for for synchronizing threads and the other is for doing actual business operations.

I have thread BLOCK issue. Please help me. In my class, i have two objects. One is for for synchronizing threads and the other is for doing actual business operations.

Here is my Class

Class A{
   Object lock = new Object();
   B b = new B();

  public addSomething(){
    synchronized(lock){
       b.doThis();
   }
  }
}

I have a single instance of class A that is 'a' and from multiple threads accessing the method a.addSomething(). I开发者_运维技巧 am encountering thread BLOCK issue for this.


The problem probably is in b.doThis(). If it isn't well-behaved (it takes a very long time to execute or may never finish) all other threads that call addSomething will be blocked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号