java - What if I start a thread in infinite loop and update my database? -
class sendmail implements runnable { thread oraclebakthread; thread sleepthread = new thread(this); public static void main(string args[]){ sendmail objsendmail= new sendmail(); objsendmail.startinfiniteloop(); } public void startinfiniteloop() { for(;;) { sleepthread.sleep(1000); oraclebakthread = new thread(this); oraclebakthread.start();} } public void getbackupfun() { dbconnectionfactory objdbconnectionfactory = new dbconnectionfactory(); properties props = new properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); query = "check if database false"; while (rs.next()) { // if database true, send mail, update database } } public void run() { int minute=0; calendar calender = calendar.getinstance(); minute=calender.get(calendar.minute); if (minute==25) { getbackupfun(); } } }
and suppose database is
id b_status 1 false 2 false 3 false
so question is, every time create new thread run method update row. thread creation inside infinite loop, how update work?
will keep on updating database?
or, first thread update first row, second update second?
but thread creation inside infinite loop, how updation work?
this denpends on update logic, code inside run()
needed.
also probaply cause errors since infinite loop keep creating new treads although ones might not finished.
Comments
Post a Comment