Created
November 23, 2025 03:28
-
-
Save ssingfly32/1a9bf191e44ccc0d01a8ce070c8666e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 김상희 | |
| class UserTask implements Runnable { | |
| private ThreadLocal<String> threadLocalValue; | |
| private String userInfo; | |
| public UserTask(ThreadLocal<String> threadLocal, String userInfo) { | |
| this.threadLocalValue = threadLocal; | |
| this.userInfo = userInfo; | |
| } | |
| @Override | |
| public void run() { | |
| threadLocalValue.set(userInfo); | |
| System.out.println(Thread.currentThread().getName() + " 로그인: " + threadLocalValue.get()); | |
| threadLocalValue.remove(); | |
| } | |
| } | |
| public class ThreadLocalAssignment { | |
| public static void main(String[] args) { | |
| ThreadLocal<String> threadLocalValue = new ThreadLocal<>(); | |
| Thread thread1 = new Thread(new UserTask(threadLocalValue, "사용자 A")); | |
| Thread thread2 = new Thread(new UserTask(threadLocalValue, "사용자 B")); | |
| thread1.start(); | |
| thread2.start(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment