11:40 pm - Saturday August 18, 2018

Thread Example program for holdsLock(Object obj)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**
*@author: candidjava.com
*@description: coding for holdslock in thread
*/

public class HoldsLock implements Runnable {

static Thread th;// creating thread

public HoldsLock() { // constructor using
th = new Thread(this);
th.start();
}

public void run() { // start the thread
System.out.println(this.getClass() + ", Hold Lock "
+ Thread.holdsLock(this));// holdslock
synchronized (this) {
System.out.println(this.getClass() + ", Hold Lock "
+ Thread.holdsLock(this));// holdslock
}
try { // exception try ,catch
th.wait();
} catch (Exception e) {
e.getMessage();
}
}

public static void main(String[] args) {
new HoldsLock();
}
}


output
class HoldsLock, Hold Lock false
class HoldsLock, Hold Lock true

Filed in: Z-A All Java Codes

Comments are closed.