• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 27451
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sudhakar Sharma is correct. sleep() does not release locks.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()?
 
Master Rancher
Posts: 4325
59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic