• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.concurrent Thread Management  RSS feed

 
Siva Arun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread 1 reads and print the XML for every 10 seconds.
Thread 2 looks for the user input in the console. If the user types 'STOP', both the threads has to be terminated.

Could you please guide me implement this by using java.util.concurrent classes(executor?)?
Thanks in advance.
 
Mike Peters
Ranch Hand
Posts: 67
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the main thread spawn a new task which does your XML processing using an ExecutorService from Executors. In the main thread you wait for the user input. If the user enter the desired input interrupt the task of the XML-thread.
 
Siva Arun
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. It works perfect as expected.

 
Vadym Ustymenko
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.concurrent is a great package when used appropriately. However, ppl tend to over complicate things... Why do you need to spawn multi-threading for this kind of task, which seems to be a straightforward single-thread job? Check out this article on thread-safe programming principles avoiding synchronization: http://javatip.com/2010/07/core-java/concurrency/thread-safe-without-synchronization/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!