In my software suite, which is a complex mesh of modular clients linked to a central server taking long-term timelapse photography, I have added the ability to update the software.
byte[] file = recieve();
FileOutputStream fos = new FileOutputStream("software.jar");
fos.flush(); fos.write(file); fos.close();
After this process is completed, there are a series of steps the client takes before it reboots. Of these processes, they include long periods of thread sleeping, file read and writing, and networking interactions.
I have not pinpointed what may or may not be the error, however, in some cases, I have observed a crash with an hs_err_pid.log.
I also have a variable, final and static, called "SOFTWARE_VERSION". I have confirmed that this variable does update (when observing from the server interface) without a reboot of the software after I replace it.
After some careful consideration, however, I've decided to immediately reboot the machine after a software update (this program will execute on startup). Since the integrity of an update has been observed to not be reliable, I found it best to give it a fresh start. It's possible (not tested) to run an action like this:
Runtime.getRuntime().exec("sudo java -jar software.jar");
System.exit(0);
However, I don't know how reliable that would be. You could also try to run something like:
Runtime.getRuntime().exec("run_software.sh")
System.exit(0);
Then in run_software.sh:
sleep 1000
sudo java -jar software.jar
I would be interested to know if that would work.
Hope this helps!