Created
July 29, 2020 17:19
-
-
Save AnjaliManhas/2e0adb39f197aba17b94888bf2de6e5f to your computer and use it in GitHub Desktop.
illustrating the use of various ThreadLocal methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wordpress.compilationerrors; | |
import java.lang.Thread; | |
import java.lang.Runnable; | |
import java.lang.*; | |
// illustrating the use of get(), set(), and remove() ThreadLocal methods | |
class ThreadLocalExp { | |
public static void main(String[] args) | |
{ | |
ThreadLocal<Number> anjaliNumber = new ThreadLocal<Number>(); | |
ThreadLocal<String> anjaliString = new ThreadLocal<String>(); | |
// setting the value | |
anjaliNumber.set(100); | |
// returns the current thread's value | |
System.out.println("value = " + anjaliNumber.get()); | |
// setting the value | |
anjaliNumber.set(90); | |
// returns the current thread's value of | |
System.out.println("value = " + anjaliNumber.get()); | |
// setting the value | |
anjaliNumber.set(88.45); | |
// returns the current thread's value of | |
System.out.println("value = " + anjaliNumber.get()); | |
// setting the value | |
anjaliString.set("compilationErrors"); | |
// returns the current thread's value of | |
System.out.println("value = " + anjaliString.get()); | |
// removing value | |
anjaliString.remove(); | |
// returns the current thread's value of | |
System.out.println("value = " + anjaliString.get()); | |
// removing vale | |
anjaliNumber.remove(); | |
// returns the current thread's value of | |
System.out.println("value = " + anjaliNumber.get()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment