1.CopyOnWriteArrayList和CopyOnWriteArraySet线程安全的集合,当生成迭代器的时候改变数组内容,不抛异常.迭代器引用的依然是旧数组
2.FutureTask包装 Future 和 Callable
public FutureTask(Runnable runnable,V result)
包装runnable成功后返回 result (指定结果可以用null)
3.线程池 ExecutorService
void shutdown()
关闭服务,会先完成那些已经提交的了的任务,但不再接受新的任务.
shutdownNow()
联消所有还有开始的任务并试图中断正在运行的线程.
4.控制线程组
T invokeAny(Collection<Callable<T>> tasks)
T invokeAny(Collection<Callable<T>> tasks,long timeout,TimeUnit unit)
执行给定的任务并返回其中之一的结果.第二个方法在发生超时时抛出一个TimeoutException异常.
List<Future<T>> invokeAll(Collection<Callable<T>> tasks)
List<Future<T>> invokeAll(Collection<Callable<T>> tasks,long timeout,TimeUnit unit)
执行给定的任务并返回它们的所有结果
ExecutorComplectionService 收集结果
ExecutorComplectionService service = new ExecutorCompletionService(executor);
for(Callable<Integer> task:tasks)
service.submit(task);
for(int i=0;i<task.size;i++)
count +=service.take().get
5.ListIterator 继承 Iterator 添加了add方法总是改变列表
6.不要使用LinkedList 的get 方法,因为非常低效.
7.TreeSet 排序Hash集合(红黑树数据结构)
8.socket 半关闭 soket.shoutdownOutput() 关闭输出流,但输入流还要开
9.查看注册的RMI服务
Context namingContext = new InitialContext();
NamingEnumeration<NameClassPair> e = nameingContext.list("rmi:");
while(e.hasMore){
System.out.println(e.next().getName());
}
10.System.setSecurityManager(new RMISecurityManager());为RMI安装安全管理器
11.每个java程序至少有三个类加载品器
1.引导加载器
2.扩展加载器
3.系统加载器
2.FutureTask包装 Future 和 Callable
MyCount count = new MyCount();
FutureTask<Integer> task = new FutureTask(count);
new Thread(task).start();
task.get();
public FutureTask(Runnable runnable,V result)
包装runnable成功后返回 result (指定结果可以用null)
3.线程池 ExecutorService
void shutdown()
关闭服务,会先完成那些已经提交的了的任务,但不再接受新的任务.
shutdownNow()
联消所有还有开始的任务并试图中断正在运行的线程.
4.控制线程组
T invokeAny(Collection<Callable<T>> tasks)
T invokeAny(Collection<Callable<T>> tasks,long timeout,TimeUnit unit)
执行给定的任务并返回其中之一的结果.第二个方法在发生超时时抛出一个TimeoutException异常.
List<Future<T>> invokeAll(Collection<Callable<T>> tasks)
List<Future<T>> invokeAll(Collection<Callable<T>> tasks,long timeout,TimeUnit unit)
执行给定的任务并返回它们的所有结果
ExecutorComplectionService 收集结果
ExecutorComplectionService service = new ExecutorCompletionService(executor);
for(Callable<Integer> task:tasks)
service.submit(task);
for(int i=0;i<task.size;i++)
count +=service.take().get
5.ListIterator 继承 Iterator 添加了add方法总是改变列表
6.不要使用LinkedList 的get 方法,因为非常低效.
7.TreeSet 排序Hash集合(红黑树数据结构)
SortedSet ss = new TreeSet();
ss.first();
ss.last();
SortedSet ssc = new TreeSet(new Comparator(){
public int compare(Object obj1,Object obj2){
return 1;
}
});
8.socket 半关闭 soket.shoutdownOutput() 关闭输出流,但输入流还要开
9.查看注册的RMI服务
Context namingContext = new InitialContext();
NamingEnumeration<NameClassPair> e = nameingContext.list("rmi:");
while(e.hasMore){
System.out.println(e.next().getName());
}
10.System.setSecurityManager(new RMISecurityManager());为RMI安装安全管理器
11.每个java程序至少有三个类加载品器
1.引导加载器
2.扩展加载器
3.系统加载器