diff --git a/start.java b/threads_test/test_1_start.java similarity index 94% rename from start.java rename to threads_test/test_1_start.java index adff86f..1737357 100644 --- a/start.java +++ b/threads_test/test_1_start.java @@ -1,7 +1,9 @@ +package threads_test; + /** * Created by Giovanni on 04/10/2014. */ -public class start { +public class test_1_start { public static class xthread implements Runnable{ @Override diff --git a/threads_test/test_2_singleton.java b/threads_test/test_2_singleton.java new file mode 100644 index 0000000..1631248 --- /dev/null +++ b/threads_test/test_2_singleton.java @@ -0,0 +1,39 @@ +package threads_test; + +/** + * Created by Giovanni on 12/10/2014. + */ +public class test_2_singleton { + + private test_2_singleton(){ + + a="initialized"; + + } + + private String a; + + + + + ////////////////////////////////////////////////////////////// + + private static class inner_test_2_singleton { + + + private static final test_2_singleton x = new test_2_singleton() ; + + } + + + + + public static test_2_singleton get_instance(){ + + return inner_test_2_singleton.x; + } + + + + +} diff --git a/threads_test/test_2_start.java b/threads_test/test_2_start.java new file mode 100644 index 0000000..02c8a94 --- /dev/null +++ b/threads_test/test_2_start.java @@ -0,0 +1,22 @@ +package threads_test; + +/** + * Created by Giovanni on 12/10/2014. + */ +public class test_2_start { + + public static void main (String[] args) { + + + test_2_singleton o= test_2_singleton.get_instance(); + test_2_singleton o2= test_2_singleton.get_instance(); + + if (o == o2 ) + System.out.print("Equal"); + + + } + + + +} diff --git a/threads_test/test_3_start_l.java b/threads_test/test_3_start_l.java new file mode 100644 index 0000000..120e1f5 --- /dev/null +++ b/threads_test/test_3_start_l.java @@ -0,0 +1,63 @@ +package threads_test; + +/** + * Created by Giovanni on 12/10/2014. + */ +public class test_3_start_l { + + + public static void main (String[] args) { + + class Thread1 implements Runnable{ + + + @Override + public void run() { + test_3_static_synchronized_lock.op1(); + } + } + + class Thread2 implements Runnable{ + + + @Override + public void run() { + test_3_static_synchronized_lock.op2(); + } + } + + class Thread3 implements Runnable{ + + + @Override + public void run() { + test_3_static_synchronized_lock.op3(); + } + } + + Thread a = new Thread(new Thread1()); + a.start(); + Thread b = new Thread(new Thread2()); + b.start(); + Thread c = new Thread(new Thread3()); + c.start(); + + try { + a.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + b.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + c.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + + } +} diff --git a/threads_test/test_3_start_m.java b/threads_test/test_3_start_m.java new file mode 100644 index 0000000..1a975a6 --- /dev/null +++ b/threads_test/test_3_start_m.java @@ -0,0 +1,63 @@ +package threads_test; + +/** + * Created by Giovanni on 12/10/2014. + */ +public class test_3_start_m { + + + public static void main (String[] args) { + + class Thread1 implements Runnable{ + + + @Override + public void run() { + test_3_static_synchronized_methods.op1(); + } + } + + class Thread2 implements Runnable{ + + + @Override + public void run() { + test_3_static_synchronized_methods.op2(); + } + } + + class Thread3 implements Runnable{ + + + @Override + public void run() { + test_3_static_synchronized_methods.op3(); + } + } + + Thread a = new Thread(new Thread1()); + a.start(); + Thread b = new Thread(new Thread2()); + b.start(); + Thread c = new Thread(new Thread3()); + c.start(); + + try { + a.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + b.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + c.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + + } +} diff --git a/threads_test/test_3_static_synchronized_lock.java b/threads_test/test_3_static_synchronized_lock.java new file mode 100644 index 0000000..bdaa346 --- /dev/null +++ b/threads_test/test_3_static_synchronized_lock.java @@ -0,0 +1,36 @@ +package threads_test; + +/** + * Created by Giovanni on 12/10/2014. + */ +public class test_3_static_synchronized_lock { + + public static void op1() { + try { + + synchronized (test_3_static_synchronized_lock.class) { + Thread.currentThread().sleep(5000); + System.out.print("OP1 eseguita"); + } + + + + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static void op2() { + synchronized (test_3_static_synchronized_lock.class) { + System.out.print("OP2 eseguita"); + } + } + + public static void op3() { + System.out.print("OP3 eseguita"); + } + + + + +} diff --git a/threads_test/test_3_static_synchronized_methods.java b/threads_test/test_3_static_synchronized_methods.java new file mode 100644 index 0000000..3754082 --- /dev/null +++ b/threads_test/test_3_static_synchronized_methods.java @@ -0,0 +1,28 @@ +package threads_test; + +/** + * Created by Giovanni on 12/10/2014. + */ +public class test_3_static_synchronized_methods { + + public static synchronized void op1() { + try { + Thread.currentThread().sleep(5000); + System.out.print("OP1 eseguita"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public static synchronized void op2() { + System.out.print("OP2 eseguita"); + } + + public static void op3() { + System.out.print("OP3 eseguita"); + } + + + + +}