- 浏览: 40032 次
- 性别:
最新评论
-
sea000sea:
感谢楼主的总结分享,刚好我在学这块内容!
json-lib.jar拼装json字符串
文章列表
package concurrent.countDownLatch;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 当调用 CountDownLatch的await方法时,所有线程阻塞
* 当CountDownLatch不断调用countDown方法使计数器减为0时,所有 ...
package concurrent.cyclicBarrier;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 设置线程路障
* await方法可以阻挡所有线程通过,当到达路障的线程数量为构造方法初始值时,就会放行
*
*/
public class CyclicBarrierTest {
public static void main( ...
package concurrent.exchanger;
import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 交换数据
* 当两个线程都到达exchanger.exchange(data)的时候就会交换数据
*/
public class ExchangerTest {
public static void main(String[] args) {
...
package concurrent.Future;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
imp ...
package concurrent.lock;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class CacheDemo {
private Map<String, Object> cache = new HashMap<String, Object>();
...
package concurrent.lock;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
/**
* 信号灯
* 只有拿到信号灯的线程才能执行,没拿到信号灯的要等待
*
*/
public class SemaphoreTest {
public static void main(String[] args) {
ExecutorService s ...
package concurrent.lock;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ConditionTest {
/**
* @param args
*/
public static void main(String[] args) {
final Business business ...
package concurrent.lock;
import java.util.Random;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class ReadWriteLockTest {
public static void main(String[] args) {
final Queue3 q3 = new Queue3();
for(int i=0;i<3;i ...
package concurrent.lock;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class PrintMsg{
private Lock lock=new ReentrantLock();
public void print(String name){
while(true){
lock.lock();
try{
for(int i=0;i<name.length();i+ ...
1、固定线程池:
package concurrent.threadpool;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 固定线程池
* 使用Executors.newFixedThreadPool(3)方法指定池中允许执行线程的个数
* 如果超过这个线程个数,后面的线程就会等待
*/
public class FixedThreadPoolTest {
public static void main(String[] ar ...
新建emp表
create table emp(
eno number,
ename varchar2(20),
sal number,
job varchar2(20),'
dept varchar2(20)
);
存储过程基本内容
--条件判断
--1、if ... then elseif then ... else ... end if;
--2、case ... when ... then ... end;
--循环结构
--1、loop ... exit when ... end loop;
--2、while ...
传统的socket IO中,需要为每个连接创建一个线程,当并发的连接数量非常巨大时,线程所占用的栈内存和CPU线程切换的开销将非常巨大。使用NIO,不再需要为每个线程创建单独的线程,可以用一个含有限数量线程的线程池,甚至一个线程来为任意数量的连接服务。由于线程数量小于连接数量,所以每个线程进行IO操作时就不能阻塞,如果阻塞的话,有些连接就得不到处理,NIO提供了这种非阻塞的能力。
小量的线程如何同时为大量连接服务呢,答案就是就绪选择。这就好比到餐厅吃饭,每来一桌客人,都有一个服务员专门为你服务,从你到餐厅到结帐走人,这样方式的好处是服务质量好,一对一的服务,VIP啊,可是缺点也很明显,成本高, ...
package thread.tongbu;
/**
* 如题:
* 子线程先执行10次,然后主线程执行100次
* 然后子线程再执行10次,主线程再执行100次
* 如此往复20次
*
*/
public class Test {
public static void main(String[] args) throws InterruptedException {
final Bus bus=new Bus();
new Thread(new Runnable() {
@Override
public v ...
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<r ...
创建型
1. Factory Method(工厂方法)
2. Abstract Factory(抽象工厂)
3. Builder(建造者)
4. Prototype(原型)
5. Singleton(单例)
结构型
6. Adapter Class/Object(适配器)
7. Bridge(桥接)
8. Composite(组合)
9. Decorator(装饰)
10. Facade(外观)
11. Flyweight(享元)
12. Proxy(代理)
行为型
13. Interpreter(解释 ...