Problem mit Threads

Status
Nicht offen für weitere Antworten.

Kaladial

Bekanntes Mitglied
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:

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
 
S

SlaterB

Gast
> also er setzt allle runnings auf false...

running ist statisch, das heißt es gibt nur einen Wert der für alle Threads gilt,
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
G 1 Socket 2 Threads problem Netzwerkprogrammierung 13
F Problem mit Threads und Sockets Netzwerkprogrammierung 3
I Socket Problem mit den WebSocket Antworten der Discord API Netzwerkprogrammierung 0
K Java Websocketserver Problem | Android to Pi Netzwerkprogrammierung 1
C RMI Produzent-Verbraucher-Problem - Code review Netzwerkprogrammierung 12
B Socket Bilder verschicken via Sockets. Heap-Problem. Netzwerkprogrammierung 2
S Problem bei dem Bluetoothverbindungsaufbau Netzwerkprogrammierung 2
G Server-Client IO Problem Netzwerkprogrammierung 6
M Netty - TCP Problem Netzwerkprogrammierung 4
L Socket Problem mit Server Netzwerkprogrammierung 1
J Chat Server starten über GUI problem Netzwerkprogrammierung 4
M Problem bei Socket (MultiplayerSpiel) Netzwerkprogrammierung 4
M Socket CDI, Websocket reference Problem ! Netzwerkprogrammierung 2
Shams Problem mit Eventbus in Verbindung mit Server Netzwerkprogrammierung 0
G apache httpClient Problem. Netzwerkprogrammierung 5
H Problem mit ObjectStreams Netzwerkprogrammierung 3
A Problem beim Senden von Client zu Server Netzwerkprogrammierung 10
D Socket BufferedWriter/Reader Problem Netzwerkprogrammierung 1
Maxim6394 Problem mit Socks5 Implementierung Netzwerkprogrammierung 0
C Handle Connection Problem Netzwerkprogrammierung 3
E HttpUrlConnection Cookie Problem Netzwerkprogrammierung 0
X Problem mit vielen Bytes über Socket Netzwerkprogrammierung 23
O 4Gewinnt Multiplayer - Netzwerk Problem (TCP) Netzwerkprogrammierung 1
A Socket Socket-Problem - Object wird nicht übertragen Netzwerkprogrammierung 3
R Problem beim Programmieren eines Chatprogramms Netzwerkprogrammierung 5
E einfaches Problem: Session-Handling bei Servlets Netzwerkprogrammierung 5
G Problem mit einem FileWatcher Netzwerkprogrammierung 7
T Socket Server starten Thread Problem Netzwerkprogrammierung 12
B Client/Server Connection Problem Netzwerkprogrammierung 2
G Problem mit STATIC-Verständnis Netzwerkprogrammierung 8
S Umstellung AS400 auf Postgre - Problem beim Arbeiten mit Metadaten Netzwerkprogrammierung 2
J Facelets Include Rendered Problem Netzwerkprogrammierung 2
J Socket Problem mit C++/Java Netzwerkprogrammierung 20
P Problem mit Datagram-Sockets Netzwerkprogrammierung 2
G Socket NIO2 Problem mit AsynchronousSocketChannel beim Schließen Netzwerkprogrammierung 3
G Cookie Verwaltungs Problem nach Login auf InetSeite (Wo utma-Cookie?) Netzwerkprogrammierung 18
C Socket Problem mit ObjectInput/OutputSream Netzwerkprogrammierung 7
B Socket Problem mit Netzwerkchat Netzwerkprogrammierung 21
D RMI Problem beim shutdown von verteilter CORBA-Anwendung Netzwerkprogrammierung 6
Maxim6394 ipv6 Problem Netzwerkprogrammierung 2
Maxim6394 Proxyserver Performance Problem Netzwerkprogrammierung 11
M Problem Client - Server Sockets: .ready() wird nie true! Netzwerkprogrammierung 6
C Socket Problem mit ObjectInput/OutputSream Netzwerkprogrammierung 5
B RMI und Problem mit rmic-Tool Netzwerkprogrammierung 3
C FTP storeFileStream Problem Netzwerkprogrammierung 3
N Problem über http eine Datei zu senden Netzwerkprogrammierung 4
D JavaMail - Mailsabrufen Problem (imap) Netzwerkprogrammierung 12
J HTTP Übersetzung yahoo babelfish - Zeichensatz-Problem Netzwerkprogrammierung 6
D Apache CXF, JAX-WS Problem bei Arrays - einfacher Server Netzwerkprogrammierung 2
M Problem beim Datenempfang Netzwerkprogrammierung 2
X Problem mit Server-Client-Kommunikation Netzwerkprogrammierung 14
M Problem mit Socket-Verbindung Netzwerkprogrammierung 2
N NIO Problem beim speziellen Behandeln von einzelnen Benutzern Netzwerkprogrammierung 13
D Thread problem Netzwerkprogrammierung 3
T Servlets JSP: Tomcat Problem Netzwerkprogrammierung 4
K Client - Server Problem Netzwerkprogrammierung 16
T RMI Problem Client-Server Netzwerkprogrammierung 2
P RMI Stub Problem Netzwerkprogrammierung 3
D Socket UDP Übertragungs Problem Netzwerkprogrammierung 7
I HTTP Post aus html in Java einlesen - Problem Netzwerkprogrammierung 2
I HTTP Post aus html in Java einlesen - Problem Netzwerkprogrammierung 6
D Problem mit ObjectInputStreams Netzwerkprogrammierung 10
D Socket Problem mit InputStreamReader Netzwerkprogrammierung 3
N CRC32 CheckSum Problem bei UDP Netzwerkprogrammierung 2
V Java Mail Api - IMAP Problem Netzwerkprogrammierung 6
P RMI Problem Netzwerkprogrammierung 4
I Problem bei Outputstreamerzeugung in anderer Klasse als Socket Netzwerkprogrammierung 5
S Socket Problem mit Objektübertragung Netzwerkprogrammierung 16
Shoox Reader / Writer Problem Netzwerkprogrammierung 2
S Problem mit 2 Serversockets unter Win XP Netzwerkprogrammierung 7
P Socket Problem mit Netzwerkverbindung über TCP Netzwerkprogrammierung 12
M RMI - Connection Problem Netzwerkprogrammierung 7
J Socket Client - Server Problem Netzwerkprogrammierung 4
M Socket Chat-Client-Problem Netzwerkprogrammierung 8
D Client Server Problem, Methode readline() löst SocketException "Connection reset" aus Netzwerkprogrammierung 8
E HTTP Problem beim Auslesen von Websiten Netzwerkprogrammierung 6
T Problem bei Findung der richtigen Architektur Netzwerkprogrammierung 3
AlexSpritze Authentication Problem bei WebServices Netzwerkprogrammierung 4
J Socket Problem -Proxies Netzwerkprogrammierung 2
R HTTP Problem bei Authentifizierung über (Http)UrlConnection Netzwerkprogrammierung 2
F Konzept Problem Netzwerkprogrammierung 12
G NIO Sockets Architektur Problem Netzwerkprogrammierung 2
H Neues NIO problem nachricht an alle clients Netzwerkprogrammierung 3
J Client server problem Netzwerkprogrammierung 3
S Problem bzgl. Sockets / Server-Client-Struktur Netzwerkprogrammierung 3
W RMI Problem Netzwerkprogrammierung 4
M Problem mit Server Netzwerkprogrammierung 5
N Socket Java server c# client problem Netzwerkprogrammierung 7
Y Problem mit ObjectInputStream beim lesen vom Socket Netzwerkprogrammierung 10
R RMI Hibernate Problem Netzwerkprogrammierung 4
Z RMI Problem Netzwerkprogrammierung 11
F RMI problem mit RMI Netzwerkprogrammierung 3
H Object Cast Problem nach Übertragung mit Log4j Netzwerkprogrammierung 5
H Log4j SocketAppender Problem Netzwerkprogrammierung 2
P HTTP Problem beim Download von einer Datei Netzwerkprogrammierung 4
P Problem mit JOscarLib Netzwerkprogrammierung 6
0din SMTP Client - readline problem Netzwerkprogrammierung 4
C komisches Problem / ObjectInputStream erstellt sich nicht Netzwerkprogrammierung 5
W vista / win server 2003 netzlaufwerk problem Netzwerkprogrammierung 4
W Problem mit HTTP-Dateiübertragung Netzwerkprogrammierung 6

Ähnliche Java Themen


Oben