forked from yrojha4ever/JavaStud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadJoinCalcTanx.java
More file actions
42 lines (32 loc) · 879 Bytes
/
ThreadJoinCalcTanx.java
File metadata and controls
42 lines (32 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package mthread;
public class ThreadJoinCalcTanx {
private double sin45;
private double cos45;
public static void main( String[] args ) {
final ThreadJoinCalcTanx obj = new ThreadJoinCalcTanx( );
Runnable sin45r = new Runnable( ) {
@Override
public void run( ) {
obj.sin45 = Math.sin( Math.PI / 4 );
}
};
Thread sin45t = new Thread( sin45r );
sin45t.start( );
Runnable cos45r = new Runnable( ) {
@Override
public void run( ) {
obj.cos45 = Math.cos( Math.PI / 4 );
}
};
Thread cos45t = new Thread( cos45r );
cos45t.start( );
try {
sin45t.join( );
cos45t.join( );
} catch ( InterruptedException e ) {
e.printStackTrace( );
}
double tan45 = Math.round( obj.sin45 / obj.cos45 );
System.out.println( "Tan45: " + tan45 ); // Nan:0.0 / 0.0;Infinity:5.0 / 0.0
}
}