diff --git a/Thread Race/nbproject/build-impl.xml b/Thread Race/nbproject/build-impl.xml index e8263ef..27eb0e4 100644 --- a/Thread Race/nbproject/build-impl.xml +++ b/Thread Race/nbproject/build-impl.xml @@ -119,43 +119,7 @@ is divided into following sections: - - - - - - - - - - - - - - - - - - - - - - - - - - Must set platform.home - Must set platform.bootcp - Must set platform.java - Must set platform.javac - - The J2SE Platform is not correctly set up. - Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. - Either open the project in the IDE and setup the Platform with the same name or add it manually. - For example like this: - ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) - or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) - + @@ -278,6 +242,20 @@ is divided into following sections: + + + + + + + + + + + + + + @@ -365,7 +343,7 @@ is divided into following sections: - + @@ -416,7 +394,7 @@ is divided into following sections: - + @@ -458,7 +436,7 @@ is divided into following sections: - + @@ -537,7 +515,7 @@ is divided into following sections: - + @@ -565,7 +543,7 @@ is divided into following sections: - + @@ -641,7 +619,7 @@ is divided into following sections: - + @@ -872,9 +850,6 @@ is divided into following sections: - - - @@ -924,7 +899,7 @@ is divided into following sections: - + @@ -958,7 +933,7 @@ is divided into following sections: - + @@ -990,7 +965,7 @@ is divided into following sections: - + @@ -1224,7 +1199,7 @@ is divided into following sections: To run this application from the command line without Ant, try: - ${platform.java} -jar "${dist.jar.resolved}" + java -jar "${dist.jar.resolved}" @@ -1326,8 +1301,8 @@ is divided into following sections: - - + + @@ -1520,19 +1495,16 @@ is divided into following sections: - - - - + - + - + diff --git a/Thread Race/nbproject/genfiles.properties b/Thread Race/nbproject/genfiles.properties index f9b38c4..22c95dd 100644 --- a/Thread Race/nbproject/genfiles.properties +++ b/Thread Race/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=7fe5bf0b +build.xml.data.CRC32=02f50314 build.xml.script.CRC32=23a17979 build.xml.stylesheet.CRC32=f85dc8f2@1.102.0.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=7fe5bf0b -nbproject/build-impl.xml.script.CRC32=28cea8aa +nbproject/build-impl.xml.data.CRC32=02f50314 +nbproject/build-impl.xml.script.CRC32=81f7ffdf nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.102.0.48 diff --git a/Thread Race/nbproject/project.properties b/Thread Race/nbproject/project.properties index dc97d8e..1641922 100644 --- a/Thread Race/nbproject/project.properties +++ b/Thread Race/nbproject/project.properties @@ -77,7 +77,7 @@ main.class=main.frmMain manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false -platform.active=JDK_11 +platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/Thread Race/nbproject/project.xml b/Thread Race/nbproject/project.xml index bba268e..791aa9a 100644 --- a/Thread Race/nbproject/project.xml +++ b/Thread Race/nbproject/project.xml @@ -4,7 +4,6 @@ Thread Race - diff --git a/Thread Race/src/main/frmMain.java b/Thread Race/src/main/frmMain.java index 980d87e..d21635f 100644 --- a/Thread Race/src/main/frmMain.java +++ b/Thread Race/src/main/frmMain.java @@ -24,42 +24,71 @@ public class frmMain extends javax.swing.JFrame { // Región Crítica int[] regionCritica = new int[3]; int posicion = 0; + int otronumero=0; /** * Creates new form frmMain */ public frmMain() { initComponents(); - this.hilo1 = new Proceso(lblNumeroHilo1); - this.hilo2 = new Proceso(lblNumeroHilo2); - this.hilo3 = new Proceso(lblNumeroHilo3); + Monitor obj = new Monitor(); +// this.hilo1 = new Proceso(lblNumeroHilo1); +// this.hilo2 = new Proceso(lblNumeroHilo2); +// this.hilo3 = new Proceso(lblNumeroHilo3); + this.hilo1 = new Proceso(lblNumeroHilo1,obj); + this.hilo2 = new Proceso(lblNumeroHilo2,obj); + this.hilo3 = new Proceso(lblNumeroHilo3,obj); regionCritica[0] = 0; regionCritica[1] = 0; regionCritica[2] = 0; } + class Monitor{ + synchronized void showMsg(String msg){ + otronumero = Integer.parseInt(msg); + regionCritica[posicion] = otronumero; + String contenidoRC = "[" + String.valueOf(regionCritica[0]) + "]"; + contenidoRC += "[" + String.valueOf(regionCritica[1]) + "]"; + contenidoRC += "[" + String.valueOf(regionCritica[2]) + "]"; + lblRegionCritica.setText(contenidoRC); + posicion++; + try{ + Thread.sleep(500); + }catch(Exception e){ + System.out.println(e); + } + } + + } + + public class Proceso extends Thread { int numeroAGenerar; + int otronumero; + Monitor m; JLabel miEtiqueta; String status; - public Proceso(JLabel etiqueta) { + public Proceso(JLabel etiqueta, Monitor m) { numeroAGenerar = 0; this.miEtiqueta = etiqueta; + this.m=m; } - + @Override public void run() { // Operaciones pre región crítica this.numeroAGenerar = (int)(Math.random()* 9 + 1); + otronumero=this.numeroAGenerar; this.miEtiqueta.setText(String.valueOf(numeroAGenerar)); // Región crítica - regionCritica[posicion] = this.numeroAGenerar; - String contenidoRC = "[" + String.valueOf(regionCritica[0]) + "]"; - contenidoRC += "[" + String.valueOf(regionCritica[1]) + "]"; - contenidoRC += "[" + String.valueOf(regionCritica[2]) + "]"; - lblRegionCritica.setText(contenidoRC); - posicion++; +// regionCritica[posicion] = this.numeroAGenerar; +// String contenidoRC = "[" + String.valueOf(regionCritica[0]) + "]"; +// contenidoRC += "[" + String.valueOf(regionCritica[1]) + "]"; +// contenidoRC += "[" + String.valueOf(regionCritica[2]) + "]"; +// lblRegionCritica.setText(contenidoRC); +// posicion++; + m.showMsg(String.valueOf(numeroAGenerar)); // Operaciones post región crítica System.out.println("Proceso finalizado con status: 0"); } @@ -208,6 +237,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }// //GEN-END:initComponents private void btnIniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIniciarActionPerformed + hilo1.start(); hilo2.start(); hilo3.start();