Monitor problem

M

Marcelo

Hello,

I have a problem with a Monitor implementation. I would like to have a
linkedList with many threads inside (for dumping Images from urls).

However, whenever I launch many threads in parallel I get an out of
Memory problem (which is normal because of the size of the images I
suppose...).

I would like to launch 10-15 threads in parellel and then let the other
threads to just wait in the linked list.

while(condition to only have 10-15 threads){
get Element from list
launch thread
}

However, i just don't know when my threads finish. How can I do it?
Do you have an idea?

thank you very much for your help,

Marcelo
 
D

dwalter

simple in your class with the will loop (called class A for now.) you
have an declaration like this: private int threadsRunning =0; and 2
synchronized functions:

public synchronized void void startThread() {
threadsRunning++;
}

public synchronized void void endThread() {
threadsRunning--;
}

and you have your threads call endThread when they end and call
startThread as you start.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top