2

I wrote a little Java program that exceedingly uses the internet connection. In multiple parallel threads the program fetches multiple websites. These threads are now intelligent enough to shut themselves down on connection timeout. I would also like them to start opening connections again the moment there is enough bandwith available. My only reasonble idea so far would be to check the current network utilization at shutdown and to start again when it sunk far enough.

How could i do this? Do you have other ideas on how to solve my problem?


Possibly useful annotation: I fetch websites via JSoup

Erik Brendel
  • 683
  • 9
  • 23

1 Answers1

0

I'd implement it using a 2 stack queue. The first stack would contain the unattended websites that have to be fetched, and the second one would be executing ones. When you get a timeout you'd have to queue the task again on the first stack, and remove it from the second.

If you handle the timeout inside the thread, you could have an infinite thread running, implementing a class that handles queuing task could give you more clean control over your program.

How to implement a queue using two stacks?

Community
  • 1
  • 1
delpo
  • 210
  • 2
  • 18