I have pictures that need to be downloaded. I want to make it so that there is one stream that downloads pictures and there is a second one that sends (for the first) download links. Tell me, please) You can not on the picture, just some kind of template)
- Can you provide the existing code so that the respondents can take into account your specific implementation? - Mikhail Rebrov
|
1 answer
The idea is the following, you have a queue with a lock it can be put into it, and read only when there is something there, otherwise it just waits.
So there will be something like this:
private BlockingQueue<String> s = new ArrayBlockingQueue<>(5); public User initThread() { try { s.put("URL"); } catch (InterruptedException e) { e.printStackTrace(); } Thread t = new Thread(()->{ try { processing(s.take()); } catch (InterruptedException e) { e.printStackTrace(); } }); } Those. when other threads put a string in the queue s , the thread t will process it.
|