This content has been marked as final. Show 4 replies
945731 wrote:You design the code, write it and test it. Standard developer tasks. If you can't do it and cannot do the research required to figure out how, there is something horribly wrong. If you're a novice there should be a senior you can turn to for guidance.
How do I stop executing the current thread and kill the processing thread and create a new thread to retry for certain number of times...
Stop executing a thread: you interrupt threads to do that (with the interrupt() method). That does not magically work, thread code needs to be designed to be interruptable. Research on your part, a good book on Threads will surely help.
Create new thread: well you already know how to do that
Certain number of times: maintain an integer that keeps track of how many times you interrupted and restarted the thread
With those three pieces of the puzzle you really must be able to put it all together yourself.
We do a similar thing in our database classes. Inside a loop, we execute a statement, and if it succeeds, we exit the loop. Else, we examine the error to see if it's a type we have determined (after years of painful experience) to be "transient." We define "transient" errors as those that may go way on their own (i.e., record locked, resource busy, etc.). If it's a transient error, and we haven't reached our (app-configurable) retry limit, we wait a specified length of time (say, a minute or two or five), then retry the statement.
Pretty simple logic, but it works wonders in our nighttime batch processing where many apps are competing for the database's attention.