Newsgroup: it.comp.java
Titolo: Thread...che ne pensate?

Ho realizzato questa classe per permettere l'avvio e la fermata di
thread...che ne pensate???
Fatemi sapere
import pCore.pApplication.Application;
/**
 * Title: Advanced Thread
 * Description: Questa classe estende thread e permette la partenza e la
fermata
 *              del thread stesso.
 * Copyright:    Copyright (c) 2000
 * Company:
 * @author Virtual Psiko
 * @version 1.0
 */
public abstract class AdvThread extends Thread{
  private static final int STATUS_NOT_INIT=-1;
  private static final int STATUS_STARTING=0;
  private static final int STATUS_STARTED=1;
  private static final int STATUS_STOPPING=2;
  private static final int STATUS_STOPPED=3;
  private int status = STATUS_NOT_INIT;
  // Oggetti per l'attesa
  private Object execwaiter=new Object();
  private Object shutwaiter=new Object();
  public abstract void startup();
  public abstract void shutdown();
  // Fa partire il thread
  public final void internalStartup() throws Exception{
    if ((status!=STATUS_STOPPED) || (status!=STATUS_NOT_INIT)){
      StringBuffer sb=new StringBuffer("Startup from state:");
      switch(status){
        case -1:
          sb.append("STATUS_NOT_INIT");
          break;
        case 0:
          sb.append("STATUS_STARTING");
          break;
        case 1:
          sb.append("STATUS_STARTED");
          break;
        case 2:
          sb.append("STATUS_STOPPING");
          break;
        case 3:
          sb.append("STATUS_STOPPED");
          break;
      }
      throw new Exception(sb.toString());
    }else{
      int oldstatus = status;
      status = STATUS_STARTING;
      startup();
      status = STATUS_STARTED;
      if (oldstatus == STATUS_NOT_INIT) start();
      execwaiter.notifyAll();
    }
  }
  // Ferma il thread
  public final void internalShutdown() throws Exception{
    if (status!=STATUS_STARTED){
      StringBuffer sb=new StringBuffer("Shutdown from state:");
      switch(status){
        case -1:
          sb.append("STATUS_NOT_INIT");
          break;
        case 0:
          sb.append("STATUS_STARTING");
          break;
        case 1:
          sb.append("STATUS_STARTED");
          break;
        case 2:
          sb.append("STATUS_STOPPING");
          break;
        case 3:
          sb.append("STATUS_STOPPED");
          break;
      }
      throw new Exception(sb.toString());
    }else{
      status=STATUS_STOPPING;
      shutwaiter.wait();
      shutdown();
      status=STATUS_STOPPED;
    }
  }
  // metodo principale del thread
  public final void run(){
    while(true){
      if ( status==STATUS_STARTED )
        overloadme();
      else{
        try{
          shutwaiter.notifyAll();
          execwaiter.wait();
        }catch(InterruptedException ex){
Application.getInstance().getLogger().error("["+getClass().getName()+"]::run
()->Errore nell\'attesa");
        }
      }
    }
  }
  // metodo su cui effettuare l'overloading per effettuare tutte le
operazioni volute
  protected abstract void overloadme();
}

Fatemi sapere
ho dato un'occhiata ma non mi e' ben chiaro 
chi determina il cambiamento di stato
ciao_O
_______________________________________
jame 4.0d is available! 
http://jame.sourceforge.net
_______________________________________
http://digilander.iol.it/schiele

 wrote in message
news:3b4c8ba5...@news.tiscalinet.it...


Ciao
ciao_O
_______________________________________
jame 4.0e is available! 
