Sincronizzazione con metodi statici: esempio 1
public class ProvaThread4 implements Runnable {
public static void main (String argv[ ]) {
ProvaThread4 pt = new ProvaThread4 ( );
Thread t = new Thread(pt);
public void run(){ m1();}
synchronized void m1 ( ) {
for (char c = 'A'; c < 'F'; c++) {
try { Thread.sleep (1000); }
catch (InterruptedException e) { } } }
static synchronized void m2 ( ) {
for (char c = '1'; c < '6'; c++) {
try {Thread.sleep (1000); }
catch (InterruptedException e) { } } }