This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

thread creation and destruction  RSS feed

 
Micheal Harris
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was working on a packet capture program am trying to capture and stop a packet capture.I am using java threads to create a thread for capture and the java JButton to stop the capture but when i recapture packets i get a Thread exception saying i have already created the thread capture but i had already "killed" interrupted the thread when i pressed stop.I know thread stop,wait etc are obsolete but i don't know where how to stop a thread. here is the code


how do i stop threads or better how can i press stop to halt a capture thread then resume it when i press capture again.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very long code, can't read it but generally once thread is stop then you can't start same thread again. New thread should be created. You can use wait/notify mechanism to inform the thread.
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thread#stop is not obsolete. It is worse: irreparably broken and it must not be used. You should also not use threads in Swing, because Swing components are not thread‑safe. Find out about worker threads; I think that will help.
 
Micheal Harris
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice forum you guys have here
sorry for the long code.....i will have a look at the links and thanks for the first reply really helped.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!