Skip to content

Instantly share code, notes, and snippets.

@AnjaliManhas
Created July 29, 2020 17:32
Show Gist options
  • Save AnjaliManhas/6ca06e2b6e9cc6013ae7001c406ca6fe to your computer and use it in GitHub Desktop.
Save AnjaliManhas/6ca06e2b6e9cc6013ae7001c406ca6fe to your computer and use it in GitHub Desktop.
illustrating the use of Java ThreadLocal initialValue method()
package com.wordpress.compilationerrors;
import java.lang.Thread;
import java.lang.Runnable;
import java.lang.*;
// illustrating the use of Java ThreadLocal initialValue() method
class NewThread extends Thread {
private static ThreadLocal anjali = new ThreadLocal(){
protected Object initialValue(){
return new Integer(a--);
}
};
private static int a = 15;
NewThread(String name)
{
super(name);
start();
}
public void run()
{
for (int i = 0; i < 2; i++)
System.out.println(getName() + " " + anjali.get());
}
}
public class ThreadLocalExp {
public static void main(String[] args)
{
NewThread t1 = new NewThread("compilationErrors1");
NewThread t2 = new NewThread("compilationErrors2");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment