Java - parallel processing deadlock -


i want try simple deadlock example. know problem in (thread t1 = new thread() { ) , ( thread t1 = new thread() { ).

the value of local variable t1 not used.

but can't fix it.

 public static void main(string[] args) {      final string passenger1 ="pick passenger1";     final string passenger2 ="pick passenger2";       thread t1 = new thread() {               public void run(){                   synchronized (passenger1) {          system.out.println("thread 1: locked passenger1 ");          try { thread.sleep(100);} catch (exception e) {}     system.out.println("thread 1: waiting passenger 2 ");         synchronized (passenger2) {         system.out.println("thread 1: locked passenger 2");                  }      }   }    };     thread t2 = new thread() {      public void run() {      synchronized (passenger2) {         system.out.println("thread 2: locked passenger2 ");         try { thread.sleep(100);}catch (exception e) {}     system.out.println("thread 2: waiting passenger1 ");       synchronized (passenger1) {          system.out.println("thread 2: locked passenger1");                     }                  }                }         };      }  } 

the warning self explanatory. define variable t1 don't use anywhere. if don't use it, nothing happen.

my program won't start when click run

most intended start thread, rather create object.

thread t1 = new thread .... // creates thread object. t1.start(); // starts thread. 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -