• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Terminating a infinite loop from within the program itself

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am making a website which has java puzzles like "fill in the missing code".
I am compiling and executing the programs online and displaying the results with respect to some test cases.
My problem is when a user tries to implement a program which goes into a infinite loop.
eg,

I want to know how I can time out programs while they are executing so I can halt the execution of programs which exceed a certain timeout or my web server will become too slow if such infinite loops are allowed to be compiled.
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Run the user code in a new thread. After a predetermined time period if the thread is still running call stop the user thread.

Have a look at this for an example:

http://www.acme.com/resources/classes/Acme/TimeKiller.java
 
V Bel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Worked for my case...
I am posting the code for further reference for other googlers. I modified your code for the infinite while loop.



Thanks a lot. This is really helpful.
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am glad it worked for you.

I modified your code for the infinite while loop



It was not my code, I found it using google.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sure hope you're installing a strict SecurityManager, or sooner rather than later, one of the "puzzle solutions" is going to pwn your server.
 
V Bel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I am working on that too.
Any suggestions on that. ?
Any useful links ?
Thanks
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

one of the "puzzle solutions" is going to pwn your server



Oops I just tried System.exit(), I guess I will have wait until you restart the server to try running System.reformatHardDrive()
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic