61 lines
1.5 KiB
Java
61 lines
1.5 KiB
Java
|
package foo.bar;
|
||
|
|
||
|
import java.lang.*;
|
||
|
import java.util.*;
|
||
|
|
||
|
class ThreadedExample
|
||
|
{
|
||
|
|
||
|
public static void printMessage(int message) {
|
||
|
System.out.println("message: " + message);
|
||
|
}
|
||
|
|
||
|
public static void printMessage(long message) {
|
||
|
System.out.println("message: " + message);
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
|
||
|
// sleep so that stap can start and byteman agent gets installed
|
||
|
try {
|
||
|
Thread.sleep(30000);
|
||
|
} catch(InterruptedException ex) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
|
||
|
|
||
|
try {
|
||
|
String[] inputs = new String[] {"int", "foo", "long"};
|
||
|
for (String next : inputs) {
|
||
|
|
||
|
final String arg = next;
|
||
|
final int i = 42;
|
||
|
final long j = 987234864;
|
||
|
Thread thread = new Thread(arg) {
|
||
|
public void run() {
|
||
|
if(arg.equals("int"))
|
||
|
printMessage(i);
|
||
|
else if(arg.equals("long"))
|
||
|
printMessage(j);
|
||
|
else
|
||
|
System.out.println("Neither of the types");
|
||
|
}
|
||
|
};
|
||
|
thread.start();
|
||
|
try {
|
||
|
thread.join();
|
||
|
} catch (Exception e){}
|
||
|
}
|
||
|
} catch (Exception e){}
|
||
|
|
||
|
|
||
|
// sleep so that stap can finish still while probed java program still runs
|
||
|
try {
|
||
|
Thread.sleep(80000);
|
||
|
} catch(InterruptedException ex) {
|
||
|
Thread.currentThread().interrupt();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|