In JAVA :
(a) Describe an application that can deadlock, or starve a thread.
(b) Describe a testing strategy that would detect such a problem efficiently.
(a) Deadlock describes a situation in which two or more threads are indefinitely separated and await each other. A Java multithreaded program that suffers from a deadlock condition because the synchronized keyword triggers blocking of the executing thread while waiting for the lock or monitor associated with the defined entity.
Go through the java program below:
public class DemoThread {
public static Object LockA = new
Object();
public static Object LockB = new
Object();
public static void main(String
args[]) {
Thread1 t1 = new Thread1();
Thread2 t2 = new Thread2();
t1.start();
t2.start();
}
private static class Thread1
extends Thread {
public void run() {
synchronized (LockA) {
System.out.println("t1- Holding
lock 1");
try { Thread.sleep(10); }
catch (InterruptedException o)
{}
System.out.println("t1- Waiting for
lock 2");
synchronized (LockB) {
System.out.println("t1- Holding
lock 1 & 2");
}
}
}
}
private static class Thread2
extends Thread {
public void run() {
synchronized (LockB) {
System.out.println("t2- Holding
lock 2");
try { Thread.sleep(10); }
catch (InterruptedException o)
{}
System.out.println("t2- Waiting for
lock 1");
synchronized (LockA) {
System.out.println("t2- Holding
lock 1 & 2");
}
}
}
}
}
The Application above will linger indefinitely because none of the threads are in a position to continue and wait for each other to unlock the lock. You can terminate it by pressing Control + c.
Output:
t1- Holding lock 1
t2- Holding lock 2
t1- Waiting for lock 2
t2- Waiting for lock 1
(b) Programmatically, threads that have reached a deadlock state can be identified and the information about them can also be recovered. ThreadMXBean interface can be used to do this. This interface comes with java.lang.Management package.
First, you need to get an instance of ThreadMXBean using ManagementFactory's getThreadMXBean() method
ThreadMXBean bn = ManagementFactory.getThreadMXBean()
Then call findMonitorDeadlockedThreads() function on it after having received an instance of ThreadMXBean. It returns a list of type long that includes ids of all currently deadlocked threads.
In JAVA : (a) Describe an application that can deadlock, or starve a thread. (b) Describe...
which of the following can occur when the only thread of a process (a process with a single thread) tries to acquire a mutex (take a lock)? a. lock contention b. lock overhead c. deadlock d. data race
7- For each of the following systems, which deadlock strategy would you lmplement? Justity a. OS running on a student laptop (1 pt) b. OS in a self-driving car (1 pt) c. Computer that can afford a deadlock for no more than 5 minutes (2 pts)
Hello, Can someone help e with this Java problem. Please ? One interesting application of computers is to display graphs and bar charts. Write an application that reads five numbers, between 1 and 30. For each number that’s read, your program should display the same number of adjacent asterisks. For example, if your program reads the number 7, it should display *******. Display the bars of asterisks after you read all five numbers. Show a few running results in the...
TRUE-FALSE Basic synchronization principles and multithreading 1. Java user threads can implement both busy-waiting and no-busy-waiting policy. 2. Priority inversion avoids deadlocks. 3. Spinlock mutex can be used as an adaptive mutex. 4. Java RTE can be blocked for Input/Output operation. 5. Interrupted user thread, which executes a method in a monitor, must be rolled back to undo any changes it performed. 6. The synchronization primitive by disabling interrupts can be used by an application program. 7. Bounded-waiting requirement is...
If an auditor decides to assess control risk as low based on IT application control procedures, which of the following would not be part of the auditor’s strategy for testing controls? a. Testing the effectiveness of management review controls used to monitor the results of operations. b. Testing the effectiveness of manual follow-up procedures. c. Testing the effectiveness of the application with test data. d. Testing the effectiveness of IT general control procedures.
java c++ 1. Write a method called deleteFromList in an application (not in the class LinkedList) with the header public static void deleteFromList (LinkedList LL, LinkedList Current) to delete all values found in linked list LL from another linked list Current. The figure below demonstrates the concept List LL 55 45 Current List 77 55 50 55 2 Current after deletion 77 50 2 2. There are many ways to detect if a phrase is a palindrome. You already learned...
Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design and code a Java console application that reads in seven integer values and prints out the number of occurrences of each value. The application uses the Java single dimension array construct to implement its functionality. Your program output should look like the sample output provided in the "Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions" course file resource. Full instructions for...
what is the solution for this Java project? Create the an application that can use different types of Linked List to manage either Checking Account or Saving Account. The application should allow users can select the type of Linked List to work on. After finishing one, users can select to work with other type of Linked List until they want to exit Singly Linked List Singly Linked List with Iterator Java Linked List with Iterator 1. 2. 3. You can...
6. Lignin can be used in adhesives but the real application has not been very successful. Please describe the reason and methods to solve this problem (10 pts).