Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Access a code at a time by only two threads  RSS feed

 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I need to write a code where there would be multiple threads. At a time only two of the Threads should be able to access a block of code in the target. Could somebody please help to implement such a logic.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By any chance, are you on jdk5?
If yes, then you can use java.util.concurrent.Semaphore.
Otherwise you can use this class from the backport of the same. This link gives information about the same.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!