users@glassfish.java.net

Re: thread name in log messages?

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Wed, 05 Sep 2012 13:46:01 -0500

There is a ctor on Thread that lets you set the name as you create it,
or you can call thread.setName() after the fact. If you don't do that,
it calculates it. Somehow. Or is your question how it calculates the
default? :)

On 09/05/2012 10:27 AM, Bobby Bissett wrote:
> Hi all,
>
> Just curious: where does the thread name come from in messages logged
> from an EE app? For instance, in GF 3.1.2.2, I have this servlet:
>
> --- begin ---
> public class TestServlet extends HttpServlet {
>
> protected void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws ServletException, IOException {
>
> resp.getWriter().println("hi there");
>
> TestThread t = new TestThread();
> t.start();
> }
>
> static class TestThread extends Thread {
>
> TestThread() {
> super("bobby_test_thread");
> }
>
> @Override
> public void run() {
> Logger.getLogger("testLogger").info("Hi, I am " + getName());
> }
> }
> }
> --- end ---
>
> ...and when accessed the log contains:
>
> [#|2012-09-05T09:45:35.156-0400|INFO|glassfish3.1.2|testLogger|_ThreadID=24;_ThreadName=Thread-4;|Hi,
> I am bobby_test_thread|#]
>
> From where does that "Thread-4" name come (and is there any way to
> have it list the thread that logged the message)?
>
> Thanks,
> Bobby


-- 
Jason Lee
Principal Member of Technical Staff
GlassFish Team
Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com