- Q Write notes on pigment effector cells.
- Q Which was the most important kingdom after the Maury in the-Deccan and Central India?
- Q In order to avoid any mishap, NGT has capped the limit for number of pilgrims visiting the Vaishno Devi shrine in Jammu and Kashmir at ___________a day.
- Q What is the difference between HTTP servlet and Generic servlet? Explain about their methods and parameters?
- Q Briefly explain Gagne’s hierarchy of learning and educational implications.
- Q Explain the @controller annotation.?
- Q Which are the structures that are part of the nervous system?
- Q Howmany five tracing levels in System.Diagnostics.TraceSwitcher? Why they are using?
- Q Special Drawing Right (SDR) created by?
- Q What is the difference between an enumeration?
- Q Mention what does the “suite test” does in TestNG?
Question
Explain how you would get a Thread Deadlock with a code example?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Answers
The example below causes a deadlock situation by thread-1 waiting for lock2 and thread-0 waiting for lock1.
package com.sushil.thread;
public class DeadlockTest extends Thread {
public static Object lock1 = new Object();
public static Object lock2 = new Object();
public void method1() {
synchronized (lock1) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“method1: ” + Thread.currentThread().getName());
synchronized (lock2) {
System.out.println(“method1 is executing …. “);
}
}
}
public void method2() {
synchronized (lock2) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“method2: ” + Thread.currentThread().getName());
synchronized (lock1) {
System.out.println(“method2 is executing …. “);
}
}
}
@Override
public void run() {
method1();
method2();
}
public static void main(String[] args) {
DeadlockTest thread1 = new DeadlockTest();
DeadlockTest thread2 = new DeadlockTest();
thread1.start();
thread2.start();
}
}
The output will be something like:
method1: Thread-1
method1 is executing ….
method1: Thread-0
method2: Thread-1 Your Comment
package com.sushil.thread;
public class DeadlockTest extends Thread {
public static Object lock1 = new Object();
public static Object lock2 = new Object();
public void method1() {
synchronized (lock1) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“method1: ” + Thread.currentThread().getName());
synchronized (lock2) {
System.out.println(“method1 is executing …. “);
}
}
}
public void method2() {
synchronized (lock2) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(“method2: ” + Thread.currentThread().getName());
synchronized (lock1) {
System.out.println(“method2 is executing …. “);
}
}
}
@Override
public void run() {
method1();
method2();
}
public static void main(String[] args) {
DeadlockTest thread1 = new DeadlockTest();
DeadlockTest thread2 = new DeadlockTest();
thread1.start();
thread2.start();
}
}
The output will be something like:
method1: Thread-1
method1 is executing ….
method1: Thread-0
method2: Thread-1 Your Comment
- 0
- 0
- New Answer
- Contributors: *,
More Software Questions..
What is the inputsplit in map reduce software?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is software configuration management?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What Is Java Api For Xml-based Rpc (jax-rpc)?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How can you implement fine-grained auditing?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is IBM’s simple explanation for Big Data’s four critical features?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is static synchronized method in JDBC API? Give an example?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What does the NULLIF function do?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What happens if a start method is not invoked and the run method is directly invoked?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Should we override finalize method
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
what is the difference between mysql_fetch_array and mysql_fetch_object?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How will XML affect my document links?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Why to use Style Sheets?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are Filters in MVC?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Can you explain Application layer in OSI model?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
How to define new testplan attributes?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
Which oracle package is used to manage the oracle lock management services?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What is marker interface?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,
What types of partitioning are there for BW?
- 0
- 0 |
- |
- Post Answer |
- Answers ( 1 )
- Tags: Software,