Java并发编程核心方法与框架-TheadPoolExecutor的使用
类ThreadPoolExecutor最常使用的构造方法是
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, unit, BlockingDeque<Runnable> workQueue)
- corePoolSize 线程池中所保存的线程数,包括空闲线程,也就是核心池的大小。当提交一个任务到线程池时,线程池会创建一个线程来执行任务,即使其他空闲的基本线程能够执行新任务也会创建线程,等到需要执行的任务数大于线程池基本大小时就不再创建。如果调用了线程池的prestartAllCoreThreads方法,线程池会提前创建并启动所有基本线程。
- maximumPoolSize 池中允许的最大线程数。如果队列满了,并且已创建的线程数小于最大线程数,则线程池会再创建新的线程执行任务。值得注意的是如果使用了无界的任务队列这个参数就没什么效果。
- keepAliveTime 当线程数量大于corePoolSize值时,在没有超过指定的时间内是不从线程池中将空闲线程删除的。如果超过此时间,则删除。所以如果任务很多,并且每个任务执行的时间比较短,可以调大这个时间,提高线程的利用率。
- unit keepAliveTime的时间单位
- workQueue 执行前用于保持任务的队列,此队列仅保持由execute方法提交的Runnable任务
ArrayBlockingQueue:是一个基于数组结构的有界阻塞队列,此队列按FIFO(先进先出)原则对元素进行排序。
LinkedBlockingQueue:一个基于链表结构的阻塞队列,此队列按FIFO(先进先出)排序元素,吞吐量通常要高于ArrayBlockingQueue。静态工厂方法Executors.newFixedThreadPool()使用了这个队列。
SynchronousQueue:一个不存储元素的阻塞队列。每个插入操作必须等到另一个线程调用移除操作,否则插入操作一直处于阻塞状态,吞吐量通常要高于LinkedBlockingQueue,静态工厂方法Executors.newCachedThreadPool使用了这个队列。
PriorityBlockingQueue:一个具有优先级的无限阻塞队列。
其他常用的构造方法参数:
- ThreadFactory:用于设置创建线程的工厂,可以通过线程工厂给每个创建出来的线程设置更有意义的名字。
- RejectedExecutionHandler(饱和策略):当队列和线程池都满了,说明线程池处于饱和状态,那么必须采取一种策略处理提交的新任务。这个策略默认情况下是AbortPolicy,表示无法处理新任务时抛出异常。以下是JDK1.5提供的四种策略。
- AbortPolicy:直接抛出异常。
- CallerRunsPolicy:只用调用者所在线程来运行任务。
- DiscardOldestPolicy:丢弃队列里最近的一个任务,并执行当前任务。
- DiscardPolicy:不处理,丢弃掉。
当然也可以根据应用场景需要来实现RejectedExecutionHandler接口自定义策略。如记录日志或持久化不能处理的任务。
当提交一个新任务到线程池时,线程池的处理流程如下:
- 线程池判断基本线程池是否已满?没满,创建一个工作线程来执行任务。满了,则进入下个流程。
- 线程池判断工作队列是否已满?没满,则将新提交的任务存储在工作队列里。满了,则进入下个流程。
- 线程池判断整个线程池是否已满?没满,则创建一个新的工作线程来执行任务,满了,则交给饱和策略来处理这个任务。
/*
* 获取基本属性corePoolSize和maximumPoolSize
*/
public class Run {
public static void main(String[] args) {
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
System.out.println(executor.getCorePoolSize());//7
System.out.println(executor.getMaximumPoolSize());//8
System.out.println("---------------------------");
SynchronousQueue<Runnable> synchronousQueue = new SynchronousQueue<>();
executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, synchronousQueue);
System.out.println(executor.getCorePoolSize());//7
System.out.println(executor.getMaximumPoolSize());//8
}
}
如果欲执行的runnable的数量<=corePoolSize,则马上创建线程运行这个任务,并且不放入扩展队列Queue中。
/**
* 队列使用LinkedBlockingDeque类,并且线程数量<=corePoolSize
* 所以keepAliveTime>5时也不清除空闲线程
*/
public class Run2_1 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//7
System.out.println("A:" + executor.getQueue().size());//0
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
}
}
//如果欲执行的runnable的数量<=corePoolSize,则马上创建线程运行这个任务,并且不放入扩展队列Queue中。
/**
* 队列使用SynchronousQueue类,并且线程数量<=corePoolSize
* 所以keepAliveTime>5时也不清除空闲线程
*/
public class Run2_2 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " begin " + System.currentTimeMillis());
TimeUnit.SECONDS.sleep(1);
System.out.println(Thread.currentThread().getName() + " end " + System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
SynchronousQueue<Runnable> workQueue = new SynchronousQueue<>();
// LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
// TimeUnit.SECONDS.sleep(10);
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//7
System.out.println("A:" + executor.getQueue().size());//0
TimeUnit.SECONDS.sleep(10);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
}
}
数量>corePoolSize&&数量<=maxmimumPoolSize的情况
/*
* BlockingQueue是一个接口,常用的实现类有LinkedBlockingQueue和ArrayBlockingQueue.
* LinkedBlockingQueue的好处在于没有大小限制,队列容量非常大,所以执行execute()不会抛出异常
* 线程池中运行的线程的数量永远也不会超过corePoolSize的值,
* 因为多余的线程被放入LinkedBlockingQueue队列中,keepAliveTime参数也就没有意义了。
*/
public class Run3_1 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
//队列使用LinkedBlockingDeque类,如果线程数量>corePoolSize时将其余的任务放入队列中。
//同一时间最多只能有7个线程执行。
//使用LinkedBlockingDeque类时,maximumPoolSize参数被忽略
LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
executor.execute(runnable);//8
//executor.execute(runnable);//8
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//7
System.out.println("A:" + executor.getQueue().size());//1
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
}
}
以上代码运行结果如下:
pool-1-thread-1 run!1470813110727
pool-1-thread-5 run!1470813110728
pool-1-thread-4 run!1470813110728
pool-1-thread-7 run!1470813110728
pool-1-thread-2 run!1470813110727
pool-1-thread-3 run!1470813110727
pool-1-thread-6 run!1470813110728
A:7
A:7
A:1
pool-1-thread-1 run!1470813111731
B:7
B:7
B:0
可见,线程pool-1-thread-1执行了两个任务。
public class Run3_2 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
/*
*队列使用SynchronousQueue类并且线程数量>corePoolSize时,将其余的线程放入池中,总数量为8
*并且线程总数量没有超过maximumPoolSize值8
*由于运行线程数为8,数量上>corePoolSize的值7
*所以keepAliveTime>5时清除空闲线程
*如果使用SynchronousQueue类则maximumPoolSize参数的作用将有效
*/
SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
executor.execute(runnable);//8
//executor.execute(runnable);//8
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//8
System.out.println("A:" + executor.getQueue().size());//0
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
//删除的是>corePoolSize的多余线程
}
}
以上代码运行结果如下:
pool-1-thread-3 run!1470832826522
pool-1-thread-6 run!1470832826522
pool-1-thread-7 run!1470832826523
pool-1-thread-5 run!1470832826522
pool-1-thread-4 run!1470832826522
pool-1-thread-1 run!1470832826522
pool-1-thread-2 run!1470832826522
pool-1-thread-8 run!1470832826523
A:7
A:8
A:0
B:7
B:7
B:0
数量>maximumPoolSize的情况
public class Run4_1 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
/*
*队列使用LinkedBlockingDeque类并且线程数量>corePoolSize时,将其余的线程放入池中
*同一时间内只有corePoolSize个线程在运行
*所以keepAliveTime>5时不清除空闲线程
*/
LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
executor.execute(runnable);//8
executor.execute(runnable);//9
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//7
System.out.println("A:" + executor.getQueue().size());//2
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
}
}
运行结果如下:
pool-1-thread-1 run!1470833462484
pool-1-thread-4 run!1470833462484
pool-1-thread-3 run!1470833462484
pool-1-thread-2 run!1470833462484
pool-1-thread-6 run!1470833462484
pool-1-thread-5 run!1470833462484
pool-1-thread-7 run!1470833462485
A:7
A:7
A:2
pool-1-thread-5 run!1470833463489
pool-1-thread-4 run!1470833463489
B:7
B:7
B:0
public class Run4_2 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 10;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
/*
*队列使用SynchronousQueue类并且线程数量>=corePoolSize
*并且线程数量<=maximumPoolSize
*所以keepAliveTime>5时清除空闲线程
*/
SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
executor.execute(runnable);//8
executor.execute(runnable);//9
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//9
System.out.println("A:" + executor.getQueue().size());//0
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
}
}
以上代码运行结果如下:
pool-1-thread-2 run!1470833720785
pool-1-thread-5 run!1470833720786
pool-1-thread-4 run!1470833720785
pool-1-thread-3 run!1470833720785
pool-1-thread-1 run!1470833720785
pool-1-thread-6 run!1470833720786
pool-1-thread-7 run!1470833720786
pool-1-thread-8 run!1470833720786
pool-1-thread-9 run!1470833720786
A:7
A:9
A:0
B:7
B:7
B:0
public class Run4_3 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 8;
int keepAliveTime = 5;
TimeUnit unit = TimeUnit.SECONDS;
/*
*队列使用SynchronousQueue类并且线程数量>corePoolSize
*并且线程数量>maximumPoolSize
*所以出现异常
*/
SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
executor.execute(runnable);//8
executor.execute(runnable);//9
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//
System.out.println("A:" + executor.getPoolSize());//
System.out.println("A:" + executor.getQueue().size());//
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//
System.out.println("B:" + executor.getPoolSize());//
System.out.println("B:" + executor.getQueue().size());//
}
}
运行结果如下:
pool-1-thread-2 run!1470833900655
pool-1-thread-6 run!1470833900655
pool-1-thread-5 run!1470833900655
pool-1-thread-4 run!1470833900655
pool-1-thread-1 run!1470833900655
pool-1-thread-7 run!1470833900656
pool-1-thread-3 run!1470833900655
pool-1-thread-8 run!1470833900656
Exception in thread "main" java.util.concurrent.RejectedExecutionException: Task com.concurrent.chapter4.concurrent07.Run4_3$1@c33f45e rejected from java.util.concurrent.ThreadPoolExecutor@6a754384[Running, pool size = 8, active threads = 8, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2048)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:821)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1372)
at com.concurrent.chapter4.concurrent07.Run4_3.main(Run4_3.java:42)
参数keepAliveTime为0时的实验
public class Run5 {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + " run!" + System.currentTimeMillis());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
int corePoolSize = 7;
int maximumPoolSize = 10;
int keepAliveTime = 0;
TimeUnit unit = TimeUnit.SECONDS;
/*
*队列使用SynchronousQueue类并且线程数量<corePoolSize
*并且线程数量<=maximumPoolSize
*并且keepAliveTime值为0时 线程执行完毕后立即清除
*/
SynchronousQueue<Runnable> workQueue = new SynchronousQueue<Runnable>();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
executor.execute(runnable);//1
executor.execute(runnable);//2
executor.execute(runnable);//3
executor.execute(runnable);//4
executor.execute(runnable);//5
executor.execute(runnable);//6
executor.execute(runnable);//7
executor.execute(runnable);//8
executor.execute(runnable);//9
Thread.sleep(300);
System.out.println("A:" + executor.getCorePoolSize());//7
System.out.println("A:" + executor.getPoolSize());//9
System.out.println("A:" + executor.getQueue().size());//0
Thread.sleep(10000);
System.out.println("B:" + executor.getCorePoolSize());//7
System.out.println("B:" + executor.getPoolSize());//7
System.out.println("B:" + executor.getQueue().size());//0
}
}
运行结果如下:
pool-1-thread-3 run!1470834464969
pool-1-thread-5 run!1470834464969
pool-1-thread-4 run!1470834464969
pool-1-thread-6 run!1470834464969
pool-1-thread-1 run!1470834464969
pool-1-thread-2 run!1470834464969
pool-1-thread-7 run!1470834464970
pool-1-thread-8 run!1470834464970
pool-1-thread-9 run!1470834464970
A:7
A:9
A:0
B:7
B:7
B:0
Java并发编程核心方法与框架-TheadPoolExecutor的使用的更多相关文章
- Java并发编程核心方法与框架-CountDownLatch的使用
Java多线程编程中经常会碰到这样一种场景:某个线程需要等待一个或多个线程操作结束(或达到某种状态)才开始执行.比如裁判员需要等待运动员准备好后才发送开始指令,运动员要等裁判员发送开始指令后才开始比赛 ...
- Java并发编程核心方法与框架-Fork-Join分治编程(一)
在JDK1.7版本中提供了Fork-Join并行执行任务框架,它的主要作用是把大任务分割成若干个小任务,再对每个小任务得到的结果进行汇总,这种开发方法也叫做分治编程,可以极大地利用CPU资源,提高任务 ...
- Java并发编程核心方法与框架-Semaphore的使用
Semaphore中文含义是信号.信号系统,这个类的主要作用就是限制线程并发数量.如果不限制线程并发数量,CPU资源很快就会被耗尽,每个线程执行的任务会相当缓慢,因为CPU要把时间片分配给不同的线程对 ...
- Java并发编程核心方法与框架-CompletionService的使用
接口CompletionService的功能是以异步的方式一边生产新的任务,一边处理已完成任务的结果,这样可以将执行任务与处理任务分离.使用submit()执行任务,使用take取得已完成的任务,并按 ...
- Java并发编程核心方法与框架-ScheduledExecutorService的使用
类SchedukedExecutorService的主要作用是可以将定时任务与线程池功能结合. 使用Callable延迟运行(有返回值) public class MyCallableA implem ...
- Java并发编程核心方法与框架-ExecutorService的使用
在ThreadPoolExecutor中使用ExecutorService中的方法 方法invokeAny()和invokeAll()具有阻塞特性 方法invokeAny()取得第一个完成任务的结果值 ...
- Java并发编程核心方法与框架-Future和Callable的使用
Callable接口与Runnable接口对比的主要优点是Callable接口可以通过Future获取返回值.但是Future接口调用get()方法取得结果时是阻塞的,如果调用Future对象的get ...
- Java并发编程核心方法与框架-Executors的使用
合理利用线程池能够带来三个好处 降低资源消耗.通过重复利用已创建的线程降低线程创建和销毁造成的消耗. 提高响应速度.当任务到达时,任务可以不需要等到线程创建就能立即执行. 提高线程的可管理性.线程是稀 ...
- Java并发编程核心方法与框架-phaser的使用
arriveAndAwaitAdvance()方法 arriveAndAwaitAdvance()作用是当前线程已经到达屏障,在此等待一段时间,等条件满足后继续向下一个屏障执行. public cla ...
随机推荐
- 【BZOJ-3337】ORZJRY I 块状链表
3337: ORZJRY I Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 190 Solved: 50[Submit][Status][Discu ...
- jdbc实现事务
//conn需要自己获取,这里我用的时springjdbcTemplate Connection conn = null; PreparedStatement pstm = null; try { c ...
- 你应该了解Nginx的7个原因
Nginx ("engine x")是一个高性能的HTTP和反向代理服务器,也是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器 1 负载均衡实 ...
- [NOIP2015] 提高组 洛谷P2661 信息传递
题目描述 有n个同学(编号为1到n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为i的同学的信息传递对象是编号为Ti同学. 游戏开始时,每人都只知道自己的生日.之后每一 ...
- Windows Directory ACL Security Check By ACL Baseline
catalog . Windows NTFS ACL(MAC) Permission . How the System Uses ACLs . 服务器不安全ACL配置带来的攻击向量 . NTFS AC ...
- MongoDB: CURD操作
>> 创建:·db.foo.insert({"bar":"baz"}) //如果文档中没有"_id"键会自动增加一个·db.fo ...
- 遵循PSR-4的自动加载
一.简介 首先这里要了解PSR,Proposing a Standards Recommendation(提出标准建议)的缩写,就是一种PHP开发规范,让我们研发出来的代码更合理.更好维护.可读性更高 ...
- 【Beta版本】冲刺-Day7
队伍:606notconnected 会议时间:12月15日 目录 一.行与思 二.站立式会议图片 三.燃尽图 四.代码Check-in 一.行与思 张斯巍(433) 今日进展:修改界面,应用图标 明 ...
- HTML5系列三(多媒体播放、本地存储、本地数据库、离线应用)
各浏览器对编码格式的支持情况 audio和video元素的属性介绍 1.src:媒体数据的URL地址 <video src="pr6.mp4"></video&g ...
- JavaWeb学习总结-07 Filter 学习和使用
一 Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态 ...