diff --git a/app/src/main/java/edu/sharif/prj01/NotThreadSafe.java b/app/src/main/java/edu/sharif/prj01/NotThreadSafe.java index 19056ae..b552c9b 100644 --- a/app/src/main/java/edu/sharif/prj01/NotThreadSafe.java +++ b/app/src/main/java/edu/sharif/prj01/NotThreadSafe.java @@ -2,11 +2,17 @@ public class NotThreadSafe{ StringBuilder builder = new StringBuilder(); + static StringBuilder staticBuilder = new StringBuilder(); + public void add(String text){ this.builder.append(text); } + public void addToStaticBuilder(String text){ + staticBuilder.append(text); + } + public static class MyRunnable implements Runnable{ NotThreadSafe instance = null; @@ -18,4 +24,16 @@ public void run(){ this.instance.add("some text"); } } + + public static class MyRunnablePrime implements Runnable{ + NotThreadSafe instance = null; + + public MyRunnablePrime(NotThreadSafe instance){ + this.instance = instance; + } + + public void run(){ + this.instance.addToStaticBuilder("some text"); + } + } } \ No newline at end of file