File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
src/CoreJava/advancedMultiThreading Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package CoreJava .advancedMultiThreading ;
2+
3+ /**
4+ * Created by dheeraj on 7/18/2016.
5+ */
6+ public class ThreadRunnableVsRun {
7+
8+ public static void main (String [] strings ) {
9+
10+ Thread t = new Thread (new Runnable () {
11+ @ Override
12+ public void run () {
13+ System .out .println ("runnable run called" );
14+ }
15+ }) {
16+ @ Override
17+ public void run () {
18+ System .out .println ("thread run called" );
19+ }
20+ };
21+ t .start ();
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ package CoreJava .advancedMultiThreading ;
2+
3+ /**
4+ * Created by dheeraj on 7/18/2016.
5+ */
6+ public class WaitNotifyDemo {
7+
8+ public static void main (String [] strings ) throws Exception {
9+ new Thread (new Runnable () {
10+ @ Override
11+ public void run () {
12+ synchronized (WaitNotifyDemo .class ) {
13+ try {
14+ WaitNotifyDemo .class .wait ();
15+ } catch (Exception e ) {
16+ }
17+ System .out .print ("waiting done" );
18+ }
19+ }
20+ }).start ();
21+ Thread .sleep (1000 );
22+
23+
24+ //above thread will only be notified after this syn is released after wait of 4 seconds
25+ synchronized (WaitNotifyDemo .class ) {
26+ WaitNotifyDemo .class .notify ();
27+ System .out .println ("notified" );
28+ Thread .sleep (4000 );
29+ }
30+ }
31+
32+
33+ }
You can’t perform that action at this time.
0 commit comments