Skip to content

Instantly share code, notes, and snippets.

@ssingfly32
Created November 23, 2025 03:28
Show Gist options
  • Select an option

  • Save ssingfly32/1a9bf191e44ccc0d01a8ce070c8666e6 to your computer and use it in GitHub Desktop.

Select an option

Save ssingfly32/1a9bf191e44ccc0d01a8ce070c8666e6 to your computer and use it in GitHub Desktop.
// 김상희
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