1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ch.qos.logback.core.issue.lbcore258;
16
17 import ch.qos.logback.core.CoreConstants;
18
19 import java.util.concurrent.*;
20 import java.util.zip.Deflater;
21
22 public class Issues877 {
23
24 static long START_TIME = System.currentTimeMillis();
25
26 static class MyRunnable implements Runnable {
27
28 final int id;
29
30 MyRunnable(int id) {
31 this.id = id;
32 }
33
34 long relativeTime() {
35 return System.currentTimeMillis()-START_TIME;
36 }
37
38 @Override
39 public void run() {
40 try {
41 System.out.println("---------"+id+" "+Thread.currentThread().getName());
42 System.out.println(relativeTime()+ " starting my runnable"+id);
43 Thread.sleep(1_000);
44 System.out.println(relativeTime()+" exiting my runnable"+id);
45 } catch (InterruptedException e) {
46 throw new RuntimeException(e);
47 }
48 }
49 };
50
51 public static void main(String[] args) throws InterruptedException {
52
53 int corePoolSize = 2;
54 int maximumPoolSize = 4;
55
56
57
58
59 ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 10L,
60 TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
61 threadPoolExecutor.allowCoreThreadTimeOut(true);
62
63
64 submit(0, threadPoolExecutor);
65
66 Thread.sleep(200);
67 submit(1, threadPoolExecutor);
68
69 Deflater deflater = new Deflater();
70
71 System.out.println("exit");
72
73 Thread.sleep(200);
74 if(1==1)
75 return;
76
77 for(int i = 0; i < 8; i++) {
78 submit(i, threadPoolExecutor);
79 }
80
81 }
82
83 private static void submit(int i, ThreadPoolExecutor threadPoolExecutor) {
84 MyRunnable myRunnable = new MyRunnable(i);
85 System.out.println("submitting "+ i);
86 threadPoolExecutor.submit(myRunnable);
87 }
88 }