How do i use ThreadLocal to make my variable Safe in a Multi-Threaded Environment?

Davanum Srinivas

Suppose you have a Configuration object that needs to be stored.

    ........
    private static ThreadLocal myConfig = new ThreadLocal();
    ........
    public static void setThreadConfig(Configuration config)
    {
        myConfig.set(config);
    }

    public static void getThreadDefaultConfig()
    {
        return (Configuration)myConfig.get();
    }
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact