public class StaticVsNonstatic {
private static String test="useme";
static int ii=0;
public static void asyncServiceMethod(){
Runnable task = new Runnable() {
@Override
public void run() {
try {
longRunningMethod();
} catch (Exception ex) {
}
}
};
new Thread(task, "ServiceThread").start();
}
public static Integer longRunningMethod() throws InterruptedException{
String test= getTest();
System.out.println(test);
return 1;
}
public static String getTest() {
ii=ii+1;
System.out.println(ii);
for (int x=0; x<1000; x++)
{
System.out.println("test");
}
return test;
}
public static void setTest(String test) {
StaticVsNonstatic.test = test;
}
public static void main(String[] argv) throws Exception {
long begin=System.currentTimeMillis();
asyncServiceMethod();
asyncServiceMethod();
asyncServiceMethod();
Thread.sleep(1000);
long end=System.currentTimeMillis();
long difference=end-begin/1000;
System.out.println(difference);
}
}
No comments:
Post a Comment