Stop a method in java -
i have made method send e-mail, , wanted try if possible call method inside method timer, scheduler
public void createexcel(){ int year = calendar.getinstance().get(calendar.year); int num_week = data.getcurrentweek()-1; arraylist<dhdemande> listedemandes = d.getdemandesforpaie(num_week, year); try { data.createfile(listedemandes); thread.sleep(20000); createexcel(); } catch(interruptedexception ex) { thread.currentthread().interrupt(); } }
but method doesn't stop (it obvious) if refresh apache , if change method. how can stop ? because receive email every 20 second
the thing treads there save way tell stop without memory leaks. can use thread.stop()
, kill thread may cause memory problems if objects big.
quote java doc:
stop()
deprecated. method inherently unsafe. stopping thread thread.stop causes unlock of monitors has locked (as natural consequence of unchecked threaddeath exception propagating stack). if of objects protected these monitors in inconsistent state, damaged objects become visible other threads, potentially resulting in arbitrary behavior. many uses of stop should replaced code modifies variable indicate target thread should stop running. target thread should check variable regularly, , return run method in orderly fashion if variable indicates stop running. if target thread waits long periods (on condition variable, example), interrupt method should used interrupt wait. more information, see why thread.stop, thread.suspend , thread.resume deprecated?.
explore thread api , see if can find else suites needs.
Comments
Post a Comment