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

48
LINES

< > BotCompany Repo | #1009311 // Java DeadLock Detection Test with ReentrantLock [WORKS]

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

Libraryless. Click here for Pure Java version (1527L/10K/38K).

!7

static Lock a = fairLock();
static Lock b = fairLock();

p-tt {
  centerHigherConsole();
  startDeadlockDetector();
  print("Initiating deadlock... :-)\n");
  
  thread "A" {
    a.lock();
    try {
      print("Thread A has lock A.");
      sleep1Second();
      print("Thread A getting lock B.");
      b.lock();
      try {
        print("Thread A sleeping.");
        main.sleep();
      } finally {
        b.unlock();
      }
    } finally {
      a.unlock();
    }
  }
  
  thread "B" {
    b.lock();
    try {
      print("Thread B has lock B.");
      sleep1Second();
      print("Thread B getting lock A.");
      a.lock();
      try {
        print("Thread B sleeping.");
        main.sleep();
       } finally {
         a.unlock();
      }
    } finally {
      b.unlock();
    }
 }
  
  sleepQuietly();
}

Author comment

Began life as a copy of #1009280

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009311
Snippet name: Java DeadLock Detection Test with ReentrantLock [WORKS]
Eternal ID of this version: #1009311/2
Text MD5: 701672e56082106851242d071d83a3ba
Transpilation MD5: 63d5507c778ddb392c58785564fb8b7f
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-23 15:13:46
Source code size: 869 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 364 / 423
Version history: 1 change(s)
Referenced in: [show references]