refactor: 重构包内容
This commit is contained in:
parent
92408bf244
commit
853b64a173
|
@ -0,0 +1,26 @@
|
||||||
|
package thead.pool;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class ThreadPoolNewCached {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
// 提交多个任务
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
final int taskId = i;
|
||||||
|
executorService.submit(() -> {
|
||||||
|
System.out.println("Task " + taskId + " executed by: " + Thread.currentThread().getName());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000); // 模拟任务执行
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭线程池
|
||||||
|
executorService.shutdown();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe0;
|
package thead.safe.safe0;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe0;
|
package thead.safe.safe0;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe1;
|
package thead.safe.safe1;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe2;
|
package thead.safe.safe2;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe3;
|
package thead.safe.safe3;
|
||||||
|
|
||||||
public class Run {
|
public class Run {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe4;
|
package thead.safe.safe4;
|
||||||
|
|
||||||
public class SynchronizedMethodLocakObject {
|
public class SynchronizedMethodLocakObject {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe4;
|
package thead.safe.safe4;
|
||||||
|
|
||||||
public class SynchronizedMethodLocakObject2 {
|
public class SynchronizedMethodLocakObject2 {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe5;
|
package thead.safe.safe5;
|
||||||
|
|
||||||
// 在多线程编程中,synchronized 关键字可以确保一个线程在执行某个方法时,其他线程无法同时访问被同步的方法,从而避免多个线程同时修改共享数据的问题。
|
// 在多线程编程中,synchronized 关键字可以确保一个线程在执行某个方法时,其他线程无法同时访问被同步的方法,从而避免多个线程同时修改共享数据的问题。
|
||||||
// 脏读(Dirty Read)指的是一个线程读取到另一个线程还未提交的修改数据,这种数据在另一个线程最终提交或者回滚后可能会发生变化,因此是不可靠的。
|
// 脏读(Dirty Read)指的是一个线程读取到另一个线程还未提交的修改数据,这种数据在另一个线程最终提交或者回滚后可能会发生变化,因此是不可靠的。
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe6;
|
package thead.safe.safe6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sychronized 锁重入指的是一个线程在获得一个锁之后,可以再次进入该锁(即再次获取锁)而不会发生死锁。
|
* sychronized 锁重入指的是一个线程在获得一个锁之后,可以再次进入该锁(即再次获取锁)而不会发生死锁。
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe7;
|
package thead.safe.safe7;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe8;
|
package thead.safe.safe8;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thread_safe.safe9;
|
package thead.safe.safe9;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
|
@ -1,4 +1,4 @@
|
||||||
package thead;
|
package thead.start;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_0;
|
package thead.start.thread_0;
|
||||||
|
|
||||||
public class DeadlockExample {
|
public class DeadlockExample {
|
||||||
private static final Object lock1 = new Object();
|
private static final Object lock1 = new Object();
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_1;
|
package thead.start.thread_1;
|
||||||
|
|
||||||
public class MyThread extends Thread {
|
public class MyThread extends Thread {
|
||||||
@Override
|
@Override
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_1;
|
package thead.start.thread_1;
|
||||||
|
|
||||||
public class ThreadApplication1 {
|
public class ThreadApplication1 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_1;
|
package thead.start.thread_1;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_2;
|
package thead.start.thread_2;
|
||||||
|
|
||||||
public class MyRunnable implements Runnable {
|
public class MyRunnable implements Runnable {
|
||||||
/**
|
/**
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_2;
|
package thead.start.thread_2;
|
||||||
|
|
||||||
public class RunnableApplication {
|
public class RunnableApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_3;
|
package thead.start.thread_3;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -12,7 +12,7 @@ public class Application {
|
||||||
MyThread myThread8 = new MyThread(8);
|
MyThread myThread8 = new MyThread(8);
|
||||||
MyThread myThread9 = new MyThread(9);
|
MyThread myThread9 = new MyThread(9);
|
||||||
MyThread myThread10 = new MyThread(10);
|
MyThread myThread10 = new MyThread(10);
|
||||||
|
|
||||||
myThread1.start();
|
myThread1.start();
|
||||||
myThread2.start();
|
myThread2.start();
|
||||||
myThread3.start();
|
myThread3.start();
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_3;
|
package thead.start.thread_3;
|
||||||
|
|
||||||
public class MyThread extends Thread {
|
public class MyThread extends Thread {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_4;
|
package thead.start.thread_4;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
// 有线程安全的操作
|
// 有线程安全的操作
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_4;
|
package thead.start.thread_4;
|
||||||
|
|
||||||
public class Application2 {
|
public class Application2 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_4;
|
package thead.start.thread_4;
|
||||||
|
|
||||||
public class MyThread extends Thread {
|
public class MyThread extends Thread {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_5;
|
package thead.start.thread_5;
|
||||||
|
|
||||||
public class Application3 {
|
public class Application3 {
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_5;
|
package thead.start.thread_5;
|
||||||
|
|
||||||
public class MyThread extends Thread {
|
public class MyThread extends Thread {
|
||||||
@Override
|
@Override
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_5;
|
package thead.start.thread_5;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_6;
|
package thead.start.thread_6;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_6;
|
package thead.start.thread_6;
|
||||||
|
|
||||||
public class Run {
|
public class Run {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_6;
|
package thead.start.thread_6;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_6;
|
package thead.start.thread_6;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_7;
|
package thead.start.thread_7;
|
||||||
|
|
||||||
public class Run {
|
public class Run {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_7;
|
package thead.start.thread_7;
|
||||||
|
|
||||||
public class Service {
|
public class Service {
|
||||||
public synchronized static void methodB() {
|
public synchronized static void methodB() {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_7;
|
package thead.start.thread_7;
|
||||||
|
|
||||||
public class ThreadA extends Thread {
|
public class ThreadA extends Thread {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_7;
|
package thead.start.thread_7;
|
||||||
|
|
||||||
public class ThreadB extends Thread {
|
public class ThreadB extends Thread {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_8;
|
package thead.start.thread_8;
|
||||||
|
|
||||||
public class MyThread extends Thread {
|
public class MyThread extends Thread {
|
||||||
@Override
|
@Override
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_8;
|
package thead.start.thread_8;
|
||||||
|
|
||||||
public class Run {
|
public class Run {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +1,4 @@
|
||||||
package thead.thread_8;
|
package thead.start.thread_8;
|
||||||
|
|
||||||
public class Run3 {
|
public class Run3 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,6 +1,7 @@
|
||||||
package thead.thread_9;
|
package thead.start.thread_9;
|
||||||
|
|
||||||
import thead.Box;
|
|
||||||
|
import thead.start.Box;
|
||||||
|
|
||||||
public class MyThread extends Thread {
|
public class MyThread extends Thread {
|
||||||
/**
|
/**
|
|
@ -1,6 +1,7 @@
|
||||||
package thead.thread_9;
|
package thead.start.thread_9;
|
||||||
|
|
||||||
import thead.Box;
|
|
||||||
|
import thead.start.Box;
|
||||||
|
|
||||||
public class Test1 {
|
public class Test1 {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
|
@ -1,4 +0,0 @@
|
||||||
package threadPool;
|
|
||||||
|
|
||||||
public class ThreadPoolNewCached {
|
|
||||||
}
|
|
Loading…
Reference in New Issue