-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlaveToMaster.java
More file actions
25 lines (22 loc) · 795 Bytes
/
SlaveToMaster.java
File metadata and controls
25 lines (22 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.concurrent.BlockingQueue;
public class SlaveToMaster extends Thread {
private BlockingQueue<String> queue;
private String slaveName;
public SlaveToMaster(BlockingQueue<String> queue, String slaveName) {
this.queue = queue;
this.slaveName = slaveName;
}
@Override
public void run() {
try {
for (int i = 1; i <= 5; i++) {
String message = slaveName + " Message " + i;
queue.put(message); // Send message to the master
System.out.println(slaveName + " sent: " + message);
Thread.sleep(500); // Simulate time to generate the message
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}