Libraryless. Click here for Pure Java version (1516L/10K/39K).
1 | !7 |
2 | |
3 | static new O a; |
4 | static new O b; |
5 | |
6 | p-tt { |
7 | centerHigherConsole(); |
8 | |
9 | doEvery_daemon(1000, r { |
10 | L<ThreadInfo> lockingThreads = printDeadlocks(); |
11 | if (nempty(lockingThreads)) { |
12 | print("Interrupting locking threads."); |
13 | L<Thread> threads = threadInfosToThreads(lockingThreads); |
14 | print("Interrupting " + n(threads, "thread")); |
15 | for (Thread t : threads) t.interrupt(); |
16 | } |
17 | }); |
18 | |
19 | print("Initiating deadlock... :-)\n"); |
20 | |
21 | thread "A" { |
22 | synchronized(a) { |
23 | print("Thread A has lock A."); |
24 | sleep1Second(); |
25 | print("Thread A getting lock B."); |
26 | synchronized(b) { |
27 | print("Thread A sleeping."); |
28 | main.sleep(); |
29 | } |
30 | } |
31 | } |
32 | |
33 | thread "B" { |
34 | synchronized(b) { |
35 | print("Thread B has lock B."); |
36 | sleep1Second(); |
37 | print("Thread B getting lock A."); |
38 | synchronized(a) { |
39 | print("Thread B sleeping."); |
40 | main.sleep(); |
41 | } |
42 | } |
43 | } |
44 | |
45 | sleepQuietly(); |
46 | } |
Began life as a copy of #1009280
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009302 |
Snippet name: | Try to solve deadlock by interrupting threads [doesn't work] |
Eternal ID of this version: | #1009302/5 |
Text MD5: | c91656ffe357bc352657f6b96f0adda6 |
Transpilation MD5: | 9945780524a7395c7397adbe50c47bf7 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-07-22 04:38:17 |
Source code size: | 1000 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 465 / 571 |
Version history: | 4 change(s) |
Referenced in: | [show references] |