0

I am looking for a way to execute untrusted java code so that the code could not use multiple thread.Is it possible to use java security manager to restrict the untrusted code to create multiple thread.any resource or hints will be helpful.

mursalin
  • 1,151
  • 1
  • 7
  • 18

1 Answers1

0

I'm not clear on what you are asking, but I'll throw out two answers anyway.

If you are using third-party code that you don't like, and it wants to start multiple threads, then there is no way to prevent that. The big thing is that the code will fail if it blocked from starting threads.

If you want to restrict some untrusted code so that only specific classes can use it, then you would have to load it with custom classloader.

Another way to isolate this code would be to wrap it in a service and run it as a micro-service in its own JVM.

Regardless, what you are talking about sounds like a bad idea. If you don't trust it, don't use it.

Steve11235
  • 2,849
  • 1
  • 17
  • 18
  • thanks Steve11235..I want the code to fail if it wants to start multiple thread.Is it possible? – mursalin Nov 13 '17 at 21:34
  • I hate to say "no" and then get shown up. I don't know of a way of preventing that. I also think it would just cause the offending code to fail. – Steve11235 Nov 13 '17 at 23:13