Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 586671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:07:53+00:00 2026-05-13T15:07:53+00:00

I am writing web app for java learning. Using which users may compile their

  • 0

I am writing web app for java learning. Using which users may compile their code on my serwer + run that code.
Compiling is easy with JavaCompiler:

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
    CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, prepareFile(nazwa, content));

    task.call();

    List<String> returnErrors = new ArrayList<String>();
    String tmp = new String();
    for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
        tmp = String.valueOf(diagnostic.getLineNumber());
        tmp += " msg: " + diagnostic.getMessage(null);
        returnErrors.add(tmp.replaceAll("\n", " "));
    }

I manage to load class with code:

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager manager = compiler.getStandardFileManager(null, null, null);

    try {
        URL[] urls = {new URL("file:///root/"), new URL("file://C:\\serv\\Apache Tomcat 6.0.20\\bin\\")};
        ClassLoader cl_old = Thread.currentThread().getContextClassLoader();
        ClassLoader cl_new = new URLClassLoader(urls, cl_old);
        Class compiledClass = cl_new.loadClass(CLASS_NAME);
        Method myMethod = compiledClass.getMethod(METHOD_NAME);
        Object tmp = myMethod.invoke(null);
    } catch (Exception ex) {
        Logger.getLogger(ITaskCompile.class.getName()).log(Level.SEVERE, null, ex);
    }

How can i protect my app from endless loop, and evil students 😉

  1. is there any way to run that code with a lifetime ?
  2. is there any risk with memory leaks, and what can i do to fix this.
  3. is this good solution, or can you suggest something better ?

thx.
Tzim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:07:53+00:00Added an answer on May 13, 2026 at 3:07 pm

    How can i protect my app from endless loop, and evil students 😉

    You cannot in one JVM. Evil students are particularly difficult to deal with because the smart ones will figure out some way to subvert your control mechanisms.

    1) is there any way to run that code with a lifetime ?

    No, unless you run it in a separate JVM.

    2) is there any risk with memory leaks, and what can i do to fix this.

    Yes there is, and there is nothing you can do about it (apart from separate JVMs). In fact, this would be a problem even if you could kill off student programs that get stuck in loops, etc. There are probably many ways that an application can cause the Java class libraries to leak memory / resources … even after the application itself has finished and been GC’ed.

    3) is this good solution, or can you suggest something better ?

    Run each student application in a separate JVM that you launch from your server using Process and friends. You will need to write host operating system specific stuff to set execution time limits, and to kill of student applications that deadlock. Plus you’ve got all sorts of issues making sure that you don’t accidentally trash the host machine performance by firing off too many JVMs.

    A better answer is to provide each student a desktop computer or a virtual machine and let them do their own thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 325k
  • Answers 325k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have an input field called action in the form-horse-update… May 14, 2026 at 1:24 am
  • Editorial Team
    Editorial Team added an answer '/' doesn't equal string::npos since npos is required to be… May 14, 2026 at 1:24 am
  • Editorial Team
    Editorial Team added an answer Dispose will still be called. All you are doing is… May 14, 2026 at 1:24 am

Related Questions

I am investigating the use of web frameworks with my Java web-app. My basic
I am writing a web app using TurboGears, and in that app the users
As developer, I am often interested in new language feature that can make your
I am writing a JSP application and am deploying it to JBoss 5.0. When
Let me just start out by saying I am completely new to Java web

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.