-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconcurrQueue.java
More file actions
53 lines (44 loc) · 928 Bytes
/
concurrQueue.java
File metadata and controls
53 lines (44 loc) · 928 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package concurrentDemos;
import java.util.concurrent.ConcurrentLinkedQueue;
public class concurrQueue implements Runnable{
private ConcurrentLinkedQueue<String> conlinkqueue=new ConcurrentLinkedQueue<String>();
public String dequeItem()
{
if(!conlinkqueue.isEmpty())
{
System.out.println("Queue size" + conlinkqueue.size());
return conlinkqueue.remove();
}
else {
return null;
}
}
private void enqueitem(String item)
{
System.out.println("Enque the item in the queue" +item);
conlinkqueue.add(item);
}
public int getQueuSize()
{
if(!conlinkqueue.isEmpty()) {
return conlinkqueue.size();
}
else {
return 0;
}
}
@Override
public void run() {
for(int i=0;i<10;i++)
{
enqueitem("String" + i);
try {
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}