We tried to follow the example in Java Thread Example? - the example given by @Phil.
The following code snippet below - during run - gives the error:
HTTP Error 500
access denied ("java.lang.RuntimePermission" "modifyThreadGroup")
at CreateThreads.<init>(CreateThreads.java:15)
at LbaApi.doPost(LbaApi.java:32)
The error occurs when the Constructor is called "public CreateThreads(ArrayList strList)". The CreateThreads is called from the doPost method - which is shown below. We tried many options but could not resolve the error. Any advice on this error - if we are missing something here. Thanks,
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.http.*;
@SuppressWarnings("serial")
public class LbaApi extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter writer = resp.getWriter();
String threadName = "TNAME";
String inputJson = req.getParameter("inputJson");
String outputJson = "";
ArrayList<String> strList = new ArrayList<String>();
strList.add(threadName);
strList.add(inputJson);
strList.add(outputJson);
CreateThreads myThread = new CreateThreads(strList); //Line 32
myThread.start();
resp.setContentType("text/plain");
outputJson = strList.get(2);
writer.println(outputJson);
}
}
While the CreateThreads codesegment is as follows:
import java.util.ArrayList;
public class CreateThreads extends Thread {
private ArrayList<String> strList;
private String threadName;
public CreateThreads(ArrayList<String> strList) {//Line 15
this.threadName = strList.get(0);
super.setName(this.threadName);
this.strList = strList;
}
@Override
public void run() {
if (this.threadName.equals("TNAME")){
String outputJson = "{'TableA':{'field_A1':'A_11'}}";
this.strList.add(outputJson);
}
}
}