I have two linux machines. On one machine I’m using a thread which starts up an executable and another internal thread reads the data from the executable and populates the database with the values from the executable, I’m using myBatis to persist the data. Later it continuously checks if the process and the internal thread is up and running. On the other machine I have the database connected remotely which is continuously deployed every night, due to this the database is being dropped and recreated. So as the database table is not available during this build an exception:
org.apache.ibatis.exceptions.PersistenceException
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Table 'updates_table' doesn't exist
is thrown. Then the thread which is continuously checking for the process and internal thread is killed and it stops checking.
Can anyone help me how to handle the thread from not being killed and once the db is available and running it should try to repopulate the table. when the db is not available it should always keep trying until the db is available.
Thank you.
Consider switching to a system where you submit jobs to an
Executorfrom the thread pulling stuff off of the process:If an exception is thrown by your
Runnable, it will be logged, but it won’t be stopped, and it will just continue to the next job in the queue. Also note that this is using a single-threaded executor, so everything submitted will be executed one at a time, and in the order they’re submitted. If you want concurrent execution, useExecutors.newFixedThreadPool(int)orExecutors.newCachedThreadPool(). Note that this answers how to keep your thread alive. If you want to resubmit a runnable for re-execution if the job fails, change itsrunmethod to:You can add logic to this to tailor when it will try again on an exception.