[concurrency-interest] Final field set null on thread termination

sandeep bansal sandeep.bansal85 at gmail.com
Fri Oct 1 02:20:37 EDT 2010


The application is a webapp deployed in tomcat. Whenever the context is
reloaded all the logging threads are shutdown.
As soon as i add a local reference to the class instance and use that
reference everything starts working fine.

On Fri, Oct 1, 2010 at 3:36 AM, David Holmes <davidcholmes at aapt.net.au>wrote:

>  Can you show us the actual stacktrace for the NullPointerException? I
> just want to verify it is coming from where you think.
>

The stacktrace for the application as as follows:

Exception in thread "Logging Thread for: router"
java.lang.NullPointerException
    at com.spice.common.logging.LogThread.run(LogThread.java:69)

The location is exactly the line of statsLogger.shutdown and this is always
the case no matter how many times i run the application.


>
> Can you try this on a version of JDK7?
>

Downloading the jdk right now. Will post the result soon.


>  Note that the null check in run() is superfluous as statsLogger can never
> be null.
>

I snipped a large part of the code. There are a lot of different logger in
my application. If i don't want to log anything i just don't start the
thread and drop the data. I forgot to remove that part.


>
> David Holmes
>
> -----Original Message-----
> *From:* concurrency-interest-bounces at cs.oswego.edu [mailto:
> concurrency-interest-bounces at cs.oswego.edu]*On Behalf Of *sandeep bansal
> *Sent:* Thursday, 30 September 2010 11:58 PM
> *To:* concurrency-interest at cs.oswego.edu
> *Subject:* [concurrency-interest] Final field set null on thread
> termination
>
> Hi Everyone,
>
> I have a thread which is something like this:
>
> public class LogThread extends Thread {
>         ...
>     private static volatile boolean stopped;
>     private final StatisticsLogger statsLogger;
>     ...
>     public LogThread(String loggerName, Config config) {
>         statsLogger = new FileLogger(loggerName, config);
>     }
>
>     public void run() {
>         if (statsLogger == null) {
>             return;
>         }
>         while(!LogThread.stopped) {
>             try {
>                             ...
>                             statsLogger.log(logData);
>                             ...
>             } catch (Exception ex) {
>                 logger.error("Exception when logging data", ex);
>             }
>         }
>         statsLogger.shutdown();
>     }
>
>     public static final void shutdown() {
>         stopped = true;
>     }
> }
>
> http://pastie.org/1191267
>
> The problem is that whenever i shutdown the thread statsLogger.shutdown()
> throws a null pointer exception. I have no idea why this is happening. My
> java version is 1.6.0.18. Can anyone please give me a clue.
>
> --
> Regards,
> Sandeep
>
>


-- 
Regards,
Sandeep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20101001/dff20f04/attachment.html>


More information about the Concurrency-interest mailing list