moin
also hab da ma wieder nen problem...
programm sieht wie folgt aus:
ich hab ne class messungControl und ne Classe (Thread) MessungThread
in messungControl gibt es einen Vector vom Typ MessungThread und die ganzen funktionen zum starten und stoppen der threads...
in messthread gibt es eine variable running um zu sagen hier der thread is am laufen...
ich greife beim stoppen meines threads per
vector.get(i).running auf das running zu welches ich grad stoppen will
aber irgendwie stoppt der mit alle threads ... also er setzt allle runnings auf false...
wieso is das so?
hier noch n bissel quellcode:
mfg Kala
also hab da ma wieder nen problem...
programm sieht wie folgt aus:
ich hab ne class messungControl und ne Classe (Thread) MessungThread
in messungControl gibt es einen Vector vom Typ MessungThread und die ganzen funktionen zum starten und stoppen der threads...
in messthread gibt es eine variable running um zu sagen hier der thread is am laufen...
ich greife beim stoppen meines threads per
vector.get(i).running auf das running zu welches ich grad stoppen will
aber irgendwie stoppt der mit alle threads ... also er setzt allle runnings auf false...
wieso is das so?
hier noch n bissel quellcode:
Code:
public class MessungControl {
public Vector<MessungThread> threads_messung = new Vector<MessungThread>();
private int threadCount;
public boolean stop_all=false;
public MessungControl(int threadCount) {
this.threadCount=threadCount;
}
synchronized public void scannerRead() {
for (int i = 0; i < threadCount; i++) {
MessungThread thread = new MessungThread(this, i);
thread.running = true;
threads_messung.add(thread);
thread.start();
}
}
synchronized public void startRead(int com) {
MessungThread thread = new MessungThread(this, com);
thread.running = true;
threads_messung.add(thread);
thread.start();
}
public synchronized void stopThread(int com){
threads_messung.get(com).running=false;
}
public synchronized void stopAllThread(){
for(int i=0; i<threadCount; i++){
threads_messung.get(i).running=false;
}
}
public synchronized void trenneString(String data_gesamt, int comport){
....
}
public synchronized void removeThread(MessungThread thread) {
threads_messung.remove(thread);
if (threads_messung.size() == 0) {
this.notify();
stop_all=true;
}
System.out.println("threads_messung_stop:"+threads_messung.size());
}
}
Code:
package ScanControl;
public class MessungThread extends Thread{
public static boolean running=false;
private int comport;
MessungControl messung;
public MessungThread(MessungControl messung, int comport) {
this.messung=messung;
this.comport=comport;
}
public void run() {
try {
while (running) {
try {
if(running){
if(Scanner.getGeraet(comport).compareToIgnoreCase("ODI-MAC-344")==0){
String data = LoadWert.loadMesswerte(comport, "SC=03");
messung.trenneString(data, comport);
sleep(200L);
Scanner.setMessung(false, comport);
}
if(Scanner.getGeraet(comport).compareToIgnoreCase("ODH-S100-Sensor")==0){
sleep(1000L);
}
}
} catch (Exception e){System.out.println("MT2:"+e);}
}
} catch (Exception e){
System.out.println("MT1:"+e);
}finally{
System.out.println("Mess-Thread closed! "+comport);
messung.removeThread(this);
}
}
}
mfg Kala