40 seconds for a single run of a question is certainly not acceptable. Have you tried the Java questions on this website in the C and Java quiz? You'll find they take from 2 - 5 seconds.
How many test cases does your question have? If you have a lot of test cases and either:
- the prototype for the question does not use a combinator template and/or
- each test case has different standard input
then you'll be sending a separate compile-and-run job to the jobe server for every test case. Java is pretty sluggish so I could imagine 20 or more test cases taking 40 seconds.
If you're writing questions with a large number of test cases, you might want to consider an alternative way of marking the student submission, e.g. by writing your own template grader that contains all the test data within it, so you need only a single job run.
If you not using a large number of test cases and you're experiencing run times like 40 seconds for a single submission then something is seriously broken. Is it possible that some process in Moodle, Jobe or the student browser is timing out on a web request to an inaccessible site, for example?
As an aside it is possible to write question types that package up all the test cases into a single run, even when multiple standard inputs are required. You can get some hints on how to do this by opening the question authoring form, clicking customise, and reading the Template controls help. But it's tricky, and I haven't done it for Java, as I don't currently teach any courses using it.
Richard