Skip to content

5.5.3 ThreadLocalDemo的结构 #151

@karaikyo

Description

@karaikyo

章节
第一篇5.5.3 ThreadLocalDemo

相关截图或文字

public class ThreadLocalDemo {
    static class ThreadA implements Runnable {
        ...
        static class ThreadB implements Runnable {
              ...
        }

        public static void main(String[] args) {
            ThreadLocal<String> threadLocal = new ThreadLocal<>();
            new Thread(new ThreadA(threadLocal)).start();
            new Thread(new ThreadB(threadLocal)).start();
        }
    }
}

疑问
这里ThreadB类是定义在了ThreadA类里面,是否可以将ThreadB和ThreadA并列:

public class ThreadLocalDemo {
       static class ThreadA implements Runnable {...}
       static class ThreadA implements Runnable {...}
       public static void main(String[] args) {
            ThreadLocal<String> threadLocal = new ThreadLocal<>();
            new Thread(new ThreadA(threadLocal)).start();
            new Thread(new ThreadB(threadLocal)).start();
        }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions