Skip to content

Commit 4118dd0

Browse files
committed
Added some DP
1 parent a71f32f commit 4118dd0

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ConcurrencyPatterns.TS_Singleton;
2+
3+
public class Singleton {
4+
private static volatile Singleton instance;
5+
6+
private Singleton(){}
7+
8+
public static Singleton getInstance(){
9+
if(instance == null){
10+
synchronized(Singleton.class){
11+
if(instance == null){
12+
instance = new Singleton();
13+
}
14+
}
15+
}
16+
return instance;
17+
}
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ConcurrencyPatterns.ThreadPool;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
import java.util.Timer;
6+
import java.util.TimerTask;
7+
8+
public class Main {
9+
public static void main(String[] args) {
10+
ExecutorService executorService = Executors.newFixedThreadPool(3);
11+
for (int i = 0; i < 10; i++) {
12+
executorService.execute(new TestRunnable());
13+
}
14+
executorService.shutdown();
15+
}
16+
}
17+
18+
class TestRunnable implements Runnable {
19+
public void run() {
20+
synchronized (System.out){
21+
System.out.println("Running");
22+
}
23+
try {
24+
Thread.sleep(2000);
25+
synchronized (System.out){
26+
System.out.println("Finished Running");
27+
}
28+
} catch (InterruptedException e) {
29+
throw new RuntimeException(e);
30+
}
31+
}
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ConcurrencyPatterns.Thread_Adapter;
2+
3+
public class C {
4+
public void func(){
5+
System.out.println("Hello!");
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ConcurrencyPatterns.Thread_Adapter;
2+
3+
public class Main {
4+
public static void main(String[] args){
5+
RunnableC runnable = new RunnableC();
6+
Thread thread = new Thread(runnable);
7+
thread.start();
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ConcurrencyPatterns.Thread_Adapter;
2+
3+
public class RunnableC extends C implements Runnable{
4+
@Override
5+
public void run() {
6+
func();
7+
}
8+
}

0 commit comments

Comments
 (0)