Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

46
LINES

< > BotCompany Repo | #1009302 // Try to solve deadlock by interrupting threads [doesn't work]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1516L/10K/39K).

!7

static new O a;
static new O b;

p-tt {
  centerHigherConsole();
  
  doEvery_daemon(1000, r {
    L<ThreadInfo> lockingThreads = printDeadlocks();
    if (nempty(lockingThreads)) {
      print("Interrupting locking threads.");
      L<Thread> threads = threadInfosToThreads(lockingThreads);
      print("Interrupting " + n(threads, "thread"));
      for (Thread t : threads) t.interrupt();
    }
  });
  
  print("Initiating deadlock... :-)\n");
  
  thread "A" {
    synchronized(a) {
      print("Thread A has lock A.");
      sleep1Second();
      print("Thread A getting lock B.");
      synchronized(b) {
        print("Thread A sleeping.");
        main.sleep();
      }
    }
  }
  
  thread "B" {
    synchronized(b) {
      print("Thread B has lock B.");
      sleep1Second();
      print("Thread B getting lock A.");
      synchronized(a) {
        print("Thread B sleeping.");
        main.sleep();
      }
    }
  }
  
  sleepQuietly();
}

Author comment

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: 397 / 479
Version history: 4 change(s)
Referenced in: [show references]