• Post Reply Bookmark Topic Watch Topic
  • New Topic

When a thread is in sleep 1000ms - Thread.sleep(1000), does the thread unlock the resource?  RSS feed

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a thread is in sleep 1000ms (Thread.sleep(1000)), does the thread unlock the resource during the 1000ms so other threads can access the resource?
 
Sheriff
Posts: 23506
47
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What resource would that be? Perhaps a short example would explain the question?
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The resource can be a section of synchronized code or a JDBC Connection the thread uses to access DB.
 
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Matt Brown wrote:When a thread is in sleep 1000ms (Thread.sleep(1000)), does the thread unlock the resource during the 1000ms so other threads can access the resource?


I don't think thread.sleep releases the lock, it's wait()

please confirm

thanks & regards
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhakar Sharma is correct. sleep() does not release locks.
 
author
Sheriff
Posts: 23503
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Edward Harned wrote:Sudhakar Sharma is correct. sleep() does not release locks.



The Thread.sleep() method doesn't release any JDBC connections either.

Henry
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So wait() and waitFor() will cause the thread to release the resource, including the JDBC Connection?

What about join() and yield()?
 
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Matt Brown wrote:So wait() and waitFor() will cause the thread to release the resource, including the JDBC Connection?


No, waitFor() doesn't release anything. And wait() only releases the lock on the object used to call wait(), not any other resource.

Matt Brown wrote:What about join() and yield()?


These don't release anything.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!