edit: Sorry, Attach Code is still completely hosed, and for some reason the spaces aren't staying even as a Quote??
I am working with these fairly new Sun SPOT devices which are hella cool and have development tools at least 10x better than the crap that is the Tmotes. I had the choice of either or both, but the Tmote was a huge PITA to even install TinyOS and dev tools, and these Sun SPOTs work so damn hell and the Java implementation is excellent.
Anyway, I've not done threads in Java before so I'm not sure I understand this. The code below was mostly taken from some sample code. Similar sample code that does the nearly the exact same thing, do not have 'synchronized' and are called a little differently.
I didn't include all the code as it is pretty simple and everything seems to be working fine, I'm just curious on why just the Tx thread is 'synchronized' and also is this the proper way to do threads in Java? I think it makes sense to have separate threads for receive and transmit (although they are only to do one either or at a time, selectable by the switch) then have the main thread check the switch for activity. So what is the purpose of 'synchronized' and moreover what is only one of the threads marked as such?
I am working with these fairly new Sun SPOT devices which are hella cool and have development tools at least 10x better than the crap that is the Tmotes. I had the choice of either or both, but the Tmote was a huge PITA to even install TinyOS and dev tools, and these Sun SPOTs work so damn hell and the Java implementation is excellent.
Anyway, I've not done threads in Java before so I'm not sure I understand this. The code below was mostly taken from some sample code. Similar sample code that does the nearly the exact same thing, do not have 'synchronized' and are called a little differently.
I didn't include all the code as it is pretty simple and everything seems to be working fine, I'm just curious on why just the Tx thread is 'synchronized' and also is this the proper way to do threads in Java? I think it makes sense to have separate threads for receive and transmit (although they are only to do one either or at a time, selectable by the switch) then have the main thread check the switch for activity. So what is the purpose of 'synchronized' and moreover what is only one of the threads marked as such?
public class Test extends MIDlet
{
protected void startApp() throws MIDletStateChangeException
{
startReceiveThread();
startTransmitThread();
respondToSwitch(); // this thread will monitor switch press
}
private void respondToSwitch()
{
while (true)
{
... // does what name implies
}
}
private void startReceiveThread()
{
new Thread()
{
public void run()
{
while (true)
{
... // receives a radiogram
Utils.sleep(500); // sleep for 500ms
}
}
}.start();
}
synchronized private void startTransmitThread()
{
new Thread()
{
public void run()
{
while (true)
{
... // sends a radiogram
Utils.sleep(500); // sleep for 500ms
}
}
}.start();
}
} // end class