vijayjust4u Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='Thingarodu' timestamp='1372778270' post='1303910987'] Lifted from stackoverflow: [url="http://stackoverflow.com/questions/4044726/how-to-set-a-timer-in-java"]http://stackoverflow...a-timer-in-java[/url] [color=#000000][font=Arial,][b]Setting a timer[/b][/font][/color] [color=#000000][font=Arial,]First you need to create a Timer:[/font][/color] [color=#2B91AF][background=transparent]Timer[/background][/color][background=transparent] timer [/background][background=transparent]=[/background][background=transparent] [/background][color=#00008B][background=transparent]new[/background][/color][background=transparent] [/background][color=#2B91AF][background=transparent]Timer[/background][/color][background=transparent]();[/background] [color=#000000][font=Arial,]To run the task once you would do:[/font][/color] [background=transparent]timer[/background][background=transparent].[/background][background=transparent]schedule[/background][background=transparent]([/background][color=#00008B][background=transparent]new[/background][/color][background=transparent] [/background][color=#2B91AF][background=transparent]TimerTask[/background][/color][background=transparent]()[/background][background=transparent] [/background][background=transparent]{[/background] [background=transparent] [/background][color=#800000][background=transparent]@Override[/background][/color] [background=transparent] [/background][color=#00008B][background=transparent]public[/background][/color][background=transparent] [/background][color=#00008B][background=transparent]void[/background][/color][background=transparent] run[/background][background=transparent]()[/background][background=transparent] [/background][background=transparent]{[/background] [background=transparent] [/background][color=gray][background=transparent]// Your method code here[/background][/color] [background=transparent] [/background][background=transparent]}[/background] [background=transparent]},[/background][background=transparent] [/background][color=#800000][background=transparent]2[/background][/color][background=transparent]*[/background][color=#800000][background=transparent]60[/background][/color][background=transparent]*[/background][color=#800000][background=transparent]1000[/background][/color][background=transparent]);[/background] [/quote] Ee code, 2 minuted delay taruvaatha run avutundhaaa? Or runs for 2 minutes aaa? Good Data unnappudu the method is taking only 20 seconds to complete... aa scenario lo 45 seconds ikkada wait cheyyatam ... bokka kadaaa... I appreciate your response... Link to comment Share on other sites More sharing options...
ZuniorVentiyar Posted July 2, 2013 Report Share Posted July 2, 2013 orinee eshalooo .... stub ni evadu gelaka manadu .... stub ki oka object create chesthavu kadha ... akkada .setTimeout call chesyi mama ..... [quote name='Sinnababu_SillyPulka' timestamp='1372779536' post='1303911089'] I agree with you changing the stub class, I am not comfort touching auto generated stub classes. Mama, for the time being...lets assume it is not a web service, but a complicated calculation.... [/quote] Link to comment Share on other sites More sharing options...
ZuniorVentiyar Posted July 2, 2013 Report Share Posted July 2, 2013 what ever code in stub (generated classes) is with default values .... it always provide methods to update u r default values ...... try them ... for u r question you need to combine below code with threads ................. long start = System.currentTimeMillis(); long end = start + 45*1000; Your_Return_type= null; boolean iscallMade = false; while (System.currentTimeMillis() < end) { if (!iscallMade ) { Your_Return_type = // call to u r service class iscallMade = true; } } if(Your_Return_type == null) { return; // inform customers no return after 45 sec } else { do normal processing } [quote name='Sinnababu_SillyPulka' timestamp='1372779536' post='1303911089'] I agree with you changing the stub class, I am not comfort touching auto generated stub classes. Mama, for the time being...lets assume it is not a web service, but a complicated calculation.... [/quote] Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 @Sinnibaabu i did not go to all the options See this option works or not public class ControlTimerThread implements Runnable { public static void main(String args[]) { ControlTimerThread ct1 = new ControlTimerThread(); Thread t1 = new Thread(ct1, "TA"); t1.start(); try { t1.join(22*1000) ; System.out.println(t1.getName()+"stopped due to time out"); t1.interrupt() ; } catch (Exception e) { } } public void run() { System.out.println(Thread.currentThread().getName()); try { System.out.println("Thread is Started"); // make call to web service and comment below sleep.....below // sleep is for test purpoe Thread.sleep(1 * 1000); System.out.println("Thread is stopped by it self"); Thread.currentThread().interrupt() ; } catch (Exception ex) { } } } Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 write ur logic where u see the thread started (printlen) Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 but if it is web service ...then follow what JAVA01 Said...that is better option If it is not a Webservice ....like if u r reading file (huge file...so u don't want or DB connection geting late etc..u can u above logic Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 @sinni i modifed above and the working perfectly one is there...so pl try to use the above code now Link to comment Share on other sites More sharing options...
vijayjust4u Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='cherlapalli_jailer' timestamp='1372788110' post='1303911744'] @sinni i modifed above and the working perfectly one is there...so pl try to use the above code now [/quote] Thanks mama.... will try and let you know Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='HAPPYNESS' timestamp='1372778396' post='1303910994'] [img]http://stream1.gifsoup.com/view6/4751671/brahrajender-o.gif[/img] [/quote] interview questions ayyipoyaya? Ninna 50? then the doc i sent More over..see @sinni baabu posted the interview Question he faced Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 ltt for busy Happy Link to comment Share on other sites More sharing options...
chinni005 Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='cherlapalli_jailer' timestamp='1372793713' post='1303912239'] ltt for busy Happy [/quote] [size=4] [/size] Link to comment Share on other sites More sharing options...
king420 Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='cherlapalli_jailer' timestamp='1372792343' post='1303912076'] interview questions ayyipoyaya? Ninna 50? then the doc i sent More over..see @sinni baabu posted the interview Question he faced [/quote] naaku ee renditiki difference teledu Comparator vs Comparable Link to comment Share on other sites More sharing options...
king420 Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='cherlapalli_jailer' timestamp='1372793713' post='1303912239'] ltt for busy Happy [/quote] [img]http://www.desigifs.com/sites/default/files/35cqsmq.gif?1290164214[/img] Link to comment Share on other sites More sharing options...
cherlapalli_jailer Posted July 2, 2013 Report Share Posted July 2, 2013 [quote name='HAPPYNESS' timestamp='1372793855' post='1303912251'] naaku ee renditiki difference teledu Comparator vs Comparable [/quote] intiki vellaka konni example lo chooddamu....abt to leave Link to comment Share on other sites More sharing options...
ZuniorVentiyar Posted July 2, 2013 Report Share Posted July 2, 2013 Comparator -- mayaaa nuvvu neetho inko edavani ppolchavu anukoo adi comparator Comparable -- nuvvu ee DB lo ni idharu neeku istam aina vedavalani okaritho okarini polchavu anukooo adi comparable [quote name='HAPPYNESS' timestamp='1372793855' post='1303912251'] naaku ee renditiki difference teledu Comparator vs Comparable [/quote] Link to comment Share on other sites More sharing options...
Recommended Posts