javamultithreadingbluetoothprintwriterspp

java - creating new thread to randomly send data to printwriter


I'm messing arount with Bluetooth SPP. I'm using SimpleSPPClient from this thread and i'm using blk wd bc 04b demo board which is configured to just send back anything that is sent to it. I'd like to create new thread which would take PrintWriter as an argument and send data to it randomly. Will this work or does the PrintWriter work only in the thread that created it ? The end result should be that one thread is sending data over bluetooth to the board and the first should read that data.


Solution

  • Anything you create before you start a thread can be used in that thread. If you only use that object in the new thread, you can use it safely.

    In the case of PrintWriter you can use locking as well, but you don't need to in your case.