In control task1... one 2nd Check in task2... 3 4 In control task1... 5 6 Check in task2... 7 8 In contr
URGENT!!
In control task1...
one
2nd
Check in task2...
3
4
In control task1...
5
6
Check in task2...
7
8
In control task1...
9
10
Transaction completed
Check in task2...
Transaction completed
Above is the two tasks (tasks) working in sequence and printing the numbers from 1 to 10 on the screen. These tasks are two Java classes named task1 and task2 and they are connected to two different threads. These tasks alternately call the method named artir() of an object created from a class named “artis”, that is, writing the numbers to the console is done by the method named artir() in the “artis” class. You can design the parameters and return value of the artir() method as you wish. The creation of the "artis" class object, tasks and threads is seen in the following snippet.
public class Final_question1 {
public static void main(String[] args) {
increment a = new increment(1, 2, 10);
//Each task will print 2 numbers in order in the range of 1-10
task1 g1 = new task1(a);
task2 g2 = new task2(a);
Thread t1 = new Thread(g1);
Thread t2 = new Thread(g2);
t1.start();
t2.start();
}
}
Write the classes artis, task1 and task2 accordingly.
Hint: You can pass the order between tasks by sleeping the thread connected to the task that is defending its order for 1 second. You do not need to use lock and condition constructs.
Step by step
Solved in 2 steps