import java.io.*; public class Runnable_Class{ //static int i = 0; public static void main(String args[]){ int count = 0; int count_t = 0; Data dato = new Data(); System.out.println("Cuenta Actual (MAIN_THREAD): " + dato.getData()); RunnableThread rt = new RunnableThread(dato); Thread t = new Thread(rt); t.start(); while(count < 100){ synchronized(dato) { dato.incrementar(); System.out.println("Cuenta Actual (MAIN_THREAD): " + dato.getData()); } count++; } } } class RunnableThread implements Runnable{ public RunnableThread(Data d_){ d=d_; } public void run(){ int count_t = 0; while(count_t < 100){ synchronized(d) { d.decrementar(); System.out.println("Cuenta Actual (SECOND_THREAD): " + d.getData()); } count_t++; } } private Data d; } class Data { public void incrementar(){ i++; } public void decrementar(){ i--; } public int getData(){ return i; } private int i=0; }