By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,538 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,538 IT Pros & Developers. It's quick & easy.

UDP threads and safety operations?

P: n/a
hi
i'm writing an application that receive data from udp port. i want to
save all the data received in an arraylist (after that i encapsulate
them in differents classes depending of the message received). also i
want after to make some treatments to the members of this arraulist
and the most important is that the save action have to be dependant
from the treatment one. and to not lost messages while saving and also
while treating.
the problem is that i have problems with this and otherwise i loose
messages otherwise i lose treatments.
that's the code i wrote :
* the connexion
public class ConnexionUdp extends Thread
{
private static List dataUdpList;
public synchronized void run()
{

try
{
while (true)
{
datagramSocket.receive(datagramPacket);

Thread save= new Thread()

{
public synchronized void run()
{
try
{
RemplirArray.remplir (datagramPacket.getData());
}
catch (IOException e)
{

e.printStackTrace();
}
}
};
save.start();
//System.out.println(dataUdpList.size());

synchronized(ThreadTreatment.currentThread())
{
ThreadTreatment.currentThread().notify();
}

}
}
catch (IOException e1)
{

e1.printStackTrace();
}

}

* to save in the arraylist :
public class RemplirArray extends ConversionsTypes
{

public static synchronized void remplir(byte[] buffer) throws
IOException
{

ConnexionUdp.getDataUdpList().add(new Model(buffer));

//Model is a class created from the data received
}
}

* and finaly the treatment :
public class ThreadTreatment extends Thread
{
public void run()
{
while(true)
{
synchronized(this) {
try {
wait();
} catch(InterruptedException e) {
throw new RuntimeException(e);
}
}
ConnexionUdp.getDataUdpList().get(0);
Task 1
Task 2

ConnexionUdp.getDataUdpList().remove(0);
}

}
}
}

the problem is that the treatment thread is never notified. and when i
remove
the wait and notify i lose some treatment threads.
does some one has a sample code of how to do...?
thanks
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.