Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:21:07+00:00 2026-06-11T16:21:07+00:00

I’m having this weird problem when writing to a socket. The application is a

  • 0

I’m having this weird problem when writing to a socket. The application is a webapp running under Tomcat 5.5.
The functionality in question is to take a request from a servlet, do some processing and send that request to an external system via SSLSocket.

This is my MessageProcessor class:

public class MessageProcessor {

    private final int socketTimeout;
    private final int threadTimeout;

    private final ExecutorService executor = Executors.newCachedThreadPool();

    private static class Holder {
        static MessageProcessor instance = new MessageProcessor();
    }

    public static MessageProcessor instance() {
        return Holder.instance;
    }
    static {
        instance();
    }

    private MessageProcessor() {
        socketTimeout = /*get from property*/
                threadTimeout = /*get from property*/

                    //Setting Java SSL details
                    System.setProperty("javax.net.ssl.trustStore") /*from property*/;
        System.setProperty("javax.net.ssl.trustStorePassword") /*from property*/;

        socketFactory = SSLSocketFactory.getDefault();
    }

    public String submit(String msg) {
        Worker worker = new Worker(msg);
        try {
            return executor.submit(worker).get(threadTimeout,
                                               TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            e.printStackTrade();
        }
        return "";
    }

    public String submitDirect(String msg) throws Exception {
        Worker worker = new Worker(msg);
        return worker.call();
    }

    class Worker implements Callable<String> {
        private String message;

        public Worker(String requestMsg) {
            this.message = requestMsg;
        }

        public String call() throws Exception {

            socket = socketFactory.createSocket();


            StringBuilder responseSb = new StringBuilder();
            StringBuilder frameMarkerSb = new StringBuilder();
            BufferedWriter socketWriter = null;
            BufferedReader socketReader = null;

            try {

                socketWriter =
                        new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                socketWriter.write(message);
                socketWriter.flush();

                socketReader =
                        new BufferedReader(new InputStreamReader(socket.getInputStream(),
                                                                 "UTF-8"));
                /* do something else */
                /* receive response */

            } catch (InterruptedIOException e) {
                //Error handling
            } catch (Exception e) {
                //Error handling
            } finally {
                socketWriter.close();
                socketReader.close();
                socket.close();
            }
            return response;
        }
    }
}

I submit message to this MessageProcessor in the servlet in this way:

protected void doPost(HttpServletRequest req,
                      HttpServletResponse resp) throws ServletException,
                                                       IOException {

    String requestStr = req.getParameter("data");
    String responseStr = "";

    try {
        responseStr =
                MessageProcessor.instance().submit(requestStr.trim());
        responseStr =
                MessageProcessor.instance().submitDirect(requestStr.trim());
    } catch (Exception e) {
        //Error handling
    }
    resp.setContentType("text/HTML");

    resp.getWriter().write(responseStr);
}

The problem is with submit(). In submit(), the task is submitted to a cached thread pool, and it throws me this Exception. The exception is thrown at socketWriter.flush().

  2012-09-06 13:17:36,007 [http-8080-1] ERROR processor.MessageProcessor - Error submitting new task
    java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
    at java.util.concurrent.FutureTask.get(FutureTask.java:91)
    at com.scb.race.bridge.processor.MessageProcessor.submit(MessageProcessor.java:70)
    at com.scb.race.bridge.servlet.CheckServlet.doPost(CreditCheckServlet.java:31)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:843)
    at   org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:679)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1303)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.NullPointerException
    at com.scb.race.bridge.processor.MessageProcessor$MessageWorker.call(MessageProcessor.java:140)
    at com.scb.race.bridge.processor.MessageProcessor$MessageWorker.call(MessageProcessor.java:78)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

If I use submitDirect(), the call() method is called directly without submitting to a thread pool, and it works fine.

There is no issue when I tested the class in JUnit. It only happens in Tomcat.

I’d be really grateful if anybody can shed some light on this. Sorry if I put a lot of code here. It’s getting me crazy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:21:08+00:00Added an answer on June 11, 2026 at 4:21 pm

    I think I have found the cause of the problem which looks like coming from this line:

    socketFactory = SSLSocketFactory.getDefault();
    

    After putting SocketFactory into a thread local variable it works fine.

    socketFactory = new ThreadLocal<SocketFactory>(){;
        protected SocketFactory initialValue() {
            return SSLSocketFactory.getDefault();
        }
    };
    

    So my conclusion is that SSLSocketFactory is not thread-safe. I haven’t found any official documentation to back this up though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was
I am currently running into a problem where an element is coming back from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.