How To Banking Concern Represent If A Thread Holds Lock On A Item Object Inwards Java

Think nearly a scenario where you lot would bring to uncovering at the run fourth dimension that whether a Java thread has a lock on a item object e.g. uncovering out whether thread NewsReader has a lock on NewsPaper object or non ? If this questions came inwards whatsoever core coffee interview together with thence I would automatically assume that in that place could locomote at to the lowest degree 2 answers i is difficult earned raw reply which programmer would similar to figure out based on fundamentals together with other could locomote roughly rarely used API calls which are available inwards Java , yesteryear the way, this is genuinely asked to me inwards an interview of i of the biggest global Investment bank. Investment banking world, especially Cash Equities requires potent meat Java together with Multithreading skills to construct high performance, depression latency Java application to procedure millions of orders per day.



2 ways to uncovering if thread holds lock on object inwards Java

 Think nearly a scenario where you lot would bring to uncovering at the run fourth dimension that  How to banking concern stand upward for if a thread holds lock on a item object inwards Javatelephonic circular of interview. I managed to supply the logic based upon the properties of synchronized block together with wait() together with notify() method, equally shown inwards the get-go reply only he wasn't satisfied at that time.



It's mutual for many interviewers to facial expression the reply they retrieve is best together with they force until you lot surrender or you lot give them the reply they want.

1)I idea nearly IllegalMonitorStateException which wait() together with notify() methods throw when they acquire called from non-synchronized context thence I said I would telephone phone newspaper.wait() together with if this telephone phone throws an exception it way thread inwards Java is non asset the lock, otherwise thread holds the lock.

 Think nearly a scenario where you lot would bring to uncovering at the run fourth dimension that  How to banking concern stand upward for if a thread holds lock on a item object inwards Java


2) Later I discovered that thread is a static method called holdsLock(Object obj) which returns truthful or simulated based on whether threads holds a lock on the object passed.

You tin equally good banking concern stand upward for out Core Java Volume 1 - Fundamentals yesteryear Cay S. Horstmann or Java Threads 2d Editon to acquire to a greater extent than nearly Thread cast inwards Java. The get-go majority is i of the best books to acquire secrets of Java inwards easiest possible manner.

 Think nearly a scenario where you lot would bring to uncovering at the run fourth dimension that  How to banking concern stand upward for if a thread holds lock on a item object inwards Java



That's all nearly how to uncovering if a thread holds a lock on a item object inwards Java. If you lot ever demand to know this within your Java application, you lot should role the holdsLock() method of java.lang.Thread class.


Comments, Suggestions ,innovative improve answers are ever welcome.


Other Java Threading tutorial you lot may like:

Further Learning
Multithreading together with Parallel Computing inwards Java
Java Concurrency inwards Practice - The Book
Applying Concurrency together with Multi-threading to Common Java Patterns
Java Concurrency inwards Practice Bundle yesteryear Heinz Kabutz


Sumber https://javarevisited.blogspot.com/

0 Response to "How To Banking Concern Represent If A Thread Holds Lock On A Item Object Inwards Java"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel