Search code examples
spark-java

Changing Thread names


I would like to change the thread-names (in the log outputs) for Spark. Currently they are named: Thread-[ID]. I would like to change the names to something like: HTTP(S)-[ID]. Any ideas how to accomplish this?


Solution

  • I guess i found the answer myself. Just add a before filter that changes the thread name for you.

    Here my handle-method:

    public void handle(Request request, Response response) {
        Thread thread = Thread.currentThread();
        String[] parts = thread.getName().split("-");
        if (parts.length != 2)
            return;
    
        thread.setName(request.scheme().toUpperCase() + "-" + parts[1]);
    }