-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrentMapTry.java
More file actions
77 lines (64 loc) · 1.84 KB
/
ConcurrentMapTry.java
File metadata and controls
77 lines (64 loc) · 1.84 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by rism on 7/4/14.
*/
class MyThread implements Runnable
{
// private Thread t;
private String threadName;
MyThread(String name)
{
this.threadName = name;
System.out.println("Creating " + threadName);
}
public void run()
{
System.out.println("Running " + threadName);
// try
// {
for ( Integer i : ConcurrentMapTry.m.keySet())
{
ConcurrentMapTry.m.put(i, threadName);
System.out.println( i +" "+ConcurrentMapTry.m.get(i));
// Let the thread sleep for a while.
// Thread.sleep(50);
}
// }
// catch(InterruptedException e)
// {
// System.out.println("Thread "+threadName+" interrupted!");
// }
System.out.println("Thread "+threadName+" Exiting");
}
// public void start()
// {
// System.out.println("Starting " + threadName);
// if(t == null)
// {
// t = new Thread(this, threadName);
// t.start();
// }
// }
}
public class ConcurrentMapTry
{
public static ConcurrentHashMap <Integer, String> m = new ConcurrentHashMap<Integer, String>(10,0.75f,1);
public static void main(String[] args)
{
m.put(1," ");
m.put(2," ");
m.put(3," ");
m.put(4," ");
m.put(5," ");
Thread T1 = new Thread(new MyThread("Thread1"));
T1.start();
Thread T2 = new Thread(new MyThread("Thread2"));
T2.start();
Thread T3 = new Thread(new MyThread("Thread3"));
T3.start();
Thread T4 = new Thread(new MyThread("Thread4"));
T4.start();
}
}