two serial tasks slower than parallel
<p>Hi I have a webapp - and in one method I need to encrypt part of data from request and store them on disk and return response.</p>

<p>Response is in no way related to encryption.</p>

<p>The encryption is quite time demanding however. How to make threads or so properly in this problem?</p>

<p>I tried something like</p>

<p>Thread thread ...</p>

<p>thread.start();</p>

<p>or</p>

<p>JobDetail job = encryptionScheduler.getJobDetail(jobDetail.getName(), jobDetail.getGroup());</p>

<p>encryptionScheduler.scheduleJob(jobDetail,TriggerUtils.makeImmediateTrigger("encryptionTrigger",1,1)</p>

<p>I tried servlet where before encryption I close the outpuStream.</p>

<p>or: Executors.newFixedThreadPool(1);</p>

<p>But whatever I tried a client has to wait longer.</p>

<p>btw: why is that so? Can it be faster?</p>

<p>I haven't tried to start thread after context initalization and wait somehow for method needing encryption.</p>

<p>how to speed up this? </p>

<p>thank you</p>

<p>--------------EDIT:
//I use axis 1.4, where I have Handler, which in invoke method encrypt a value:</p>

<pre><code>try {
    LogFile logFile = new LogFile(strategy,nodeValue,path, new Date());
    LogQueue.queue.add(logFile);
    }
    catch (Exception e) {
        log.error(e.getMessage(),e);
    }

EExecutor.executorService.execute(new Runnable() {
            public void run() {
                try {
                LogFile poll = LogQueue.queue.poll();
                String strategy = poll.getStrategy();
                    String value = poll.getNodeValue();
                    value = encrypt(strategy,value);
                    PrintWriter writer = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(poll.getPath(), true )),"UTF-8"));
                    writer.print(value);
                    writer.close();
                }catch (IOException e  ) {
                    log.error(e.getMessage(),e);
                } 
            }

        });
        } catch (Throwable e ) {
            log.error(e.getMessage(),e);
        }
</code></pre>

<p>//besides I have executor service</p>

<pre><code>public class EExecutor { public static ExecutorService executorService = Executors.newCachedThreadPool();}
</code></pre>

<p>//and what's really interesting.. when I move encryption from this handler away into another handler which is called
last when I send response! It's faster. But when I leave it in one of the first handlers when I receive request. It's even slower without using threads/servlet etc.  </p>
