In
while (InfoListener.can_start_sender = false)
you are assigning false
to can_start_sender
. The while
will therefore always resolve to false
.
It's possible that code following the while
// write -------- HERE IS THE NULLPOINTEREXCEPTION ------------
InfoListener.output.writeBytes(string_to_send);
will get executed before the other Thread
has time to initialize the static
output
field thus causing a NullPointerException
.
Use
while (!InfoListener.can_start_sender)
or better yet use a CountDownLatch
or similar java.util.concurrent
lock object. You should also make can_start_sender
volatile
.