简体   繁体   中英

threads in a servlet Google appengine Java (for serializing data from XML to blob, pipedinput, pipedoutput)

How does one know when a Thread one started in a Google Appengine
servlet has completed its assigned tasks.

I am using pipedinput and pipedoutput to get information put XML
into a Blob. That is the XML Serializer outputs to one end of the pipe.
A thread reads the other end of the pipe and puts data into the Blob.

I know that one must use the ThreadFactory, newThread function to activate the thread One cannot use the standard technique from Java of calling Thread.start() .

T TT;
TT = new T();
java.util.concurrent.ThreadFactory TF;
TF = com.google.appengine.api.ThreadManager.currentRequestThreadFactory();
TF.newThread(TT);

Here is how I declare and create my Runnable:

class T implements Runnable {
public void run(){
FileWriteChannel writeChannel=null;
try {

Here is the code to create the Thread. Note that when I declare type T to implement the Thread, I get the security exception below:

class T implements Runnable {
public void run(){
FileWriteChannel writeChannel=null;
try {
...

If I start up a class that extends Thread, Google Appengine gives me run time error.
If I do a "implements" runnable, that is TT in the example above, is an instance
of an ojbect thwt inmpelements Thread, then, I do not have access to the join
capability, which is defined in the Thread class, but not the runnable.

Thread Error java.security.AccessControlException: access denied
("java.lang.RuntimePermission" "modifyThreadGroup")     at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:375)
    at
java.security.AccessController.checkPermission(AccessController.java:565)
    at
java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at


com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:56)
    at
com.google.apphosting.runtime.security.CustomSecurityManager.checkAccess(CustomSecurityManager.java:131)
    at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)*

I am doing the read from the PipedInputStream in a separate thread because
of the statement in the API documentation for PipedInputStream:

"A piped input stream should be connected to a piped output stream; the piped input
stream then provides whatever data bytes are written to the piped output stream.
Typically, data is read from a PipedInputStream object by one thread and data is
written to the corresponding PipedOutputStream by some other thread.
Attempting to use both objects from a single thread is not recommended,
as it may deadlock the thread. "

Dr. Laurence Leff Associate Professor of Computer Science,
Western Illinois University, Macomb IL 61455 on sabbatical

You actually get a Thread from TF.newThread(TT) . Try calling join() on it. Try this:

Thread myThread= TF.newThread(TT);
myThread.join();

Also note: currentRequestThreadFactory() creates threads scoped to the current request. Side effects of such threads is that they cannot outlive request as docs state :

Returns a ThreadFactory that will create threads scoped to the current request. These threads will be interrupted at the end of the current request and must complete within the request deadline.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM