`
文章列表
  package pattern.builder; public class BuilderDemo { public static void main(String[] args) { NutritionFacts cocaCola = new NutritionFacts.Builder(240, 8) .calories(100).sodium(35).carbohydrate(27).build(); System.out.println(cocaCola); } } /** * 建造者模式 * 1.构造函数参 ...
工厂:根据不同条件返回不同类型的对象。   工厂方法:通过子类复写父类的(抽象)方法,返回具体对象。   模板方法:定义通用的程序执行流程,某些不确定的步骤在父类中使用抽象方法进行定义,具体实现交给子类。 ...
责任链设计模式 一般原则: 当请求被责任链中某个对象处理了,则停止后续调用;否则,将请求继续往下传递。 变体: 请求可以被责任链中某几个对象处理,也可以分别被每个对象处理一遍。   Sample1: 日志记录为例,任务会依次传递到每一个对象上,至于是否处理则由具体对象来决定: DEBUGE级别的,只往控制台输出; NOTICE级别的,往控制台输出,并发送邮件; ERROR级别的,往控制台输出,并发送邮件,并将错误记录到专门的文件中;     ===》顶层接口 public interface ILogger { void log(String msg, in ...
   

【apache-commons】CLI

    博客分类:
  • Java
命令行参数解析器 用途:对命令行参数进行解析,完成应用程序的配置 比如,启动应用的时候,通过命令行指定端口,如果没有指定,则使用默认的。   package org.apache.commons.cli; public class App { public static void main(String[] args) throws ParseException { test(args); } private static void test(String[] args) throws ParseException { Options option ...
Lock&Condition   Executor 任务执行器,通过线程池来完成任务的执行。 使用线程池的好处: 仅需维护一定数量的线程去执行任务,降低频繁创建或销毁线程而带来的性能损耗。   interface ExecutorService extends Executor interface ScheduledExecutorService extends ExecutorService   Executor  属于顶层接口,仅提供了一个执行线程任务的方法 void execute(Runnable command);   ExecutorServic ...
首先,需要理解一些理论上的东西。   多个线程并发对同一个资源进行操作,很可能发生内存一致性错误。   究其原因,线程很多情况下对资源的操作不是原子的,这些代码会被分为若干条指令去执行,而在一个CPU时间片内又不能将这些指令全部执行完毕。 当多个线程同时操作同一个共享资源时,线程B拿着线程A的半成品进行操作,内存一致性错误就发生了。   如何解决? 1.同步,即:加锁。通过加锁的方式,可以确保唯一获取锁的线程可以不受干扰的执行完自己的程序片段。只有当前线程释放锁之后,其它线程才能对此资源进行操作。否则,只能等待当前线程执行完毕后释放锁(等待锁的线程全部被阻塞了);   2 ...
线程中断           //中断主线程        Thread.currentThread().interrupt();//线程自己中断自己                Thread worker = new Thread();        worker.start();                worker.interrupt();//线程A中断线程B                Thread.interrupted();//检测中断状态,并清除中断状态,中断标记置为false                worker.isInterrupted();//检测中 ...

不错的网站

  看人家讲得多透彻,要学就学这种资料,各位!!!   线程基础 http://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html   线程并发高级篇 http://docs.oracle.com/javase/tutorial/essential/concurrency/highlevel.html   HTML+CSS+JAVASCRIPT http://www.dreamdu.com/xhtml/   https://developer.mozilla.org/en-US/ ...
A single thread can monitor large numbers of channels with readiness selection. The Selectorand related classes provide the APIs todo readiness selection on channels.   Selector Basics You register one or more previously created selectable channels with a selector object.   A key that rep ...
A Channelis a conduit(管道) that transports data efficiently between byte buffers and the entity on the other end of the channel (usually a file or socket).    Basic channel operations checking to see if a channel is open (isOpen()) and closing an open channel (close()). Most, but not all, channe ...
  Buffer Basics Attributes Capacity The maximum number of data elements the buffer can hold. The capacity is set when the buffer is created and can never be changed.  指定缓冲区总容量,在分配缓冲区时指定 Limit The first element of the buffer that should not be read or written. In other words, the count ...
Encapsulation is a good thing: It partitions responsibility, hides implementation details, and promotes object reuse. 封装:按职责划分类,隐藏实现细节,提供对象重用。   IO Versus CPU Time 应用程序开发过程中,使用各种技巧将程序设计得更灵活,更优雅,更具扩展性是非常重要的。然而,很多人往往在其它方面花大力气,却忽视了另一个重要的方面:对IO操作没有给予足够的重视。 IO操作是否高效,将很大程度上影响系统的响应速度。   打个不是很恰当的比 ...

Maven插件

  插件1:生成可执行jar Maven Shade Plugin for the simple convenience of making the JAR file executable. Detail:  http://maven.apache.org/plugins/maven-shade-plugin/ <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId&g ...

Tomcat配置连接池

  Tomcat默认没有设置连接池,需要手动修改server.xml进行开启   <Service name="Catalina"> <!--The connectors can use a shared executor, you can define one or more named thread pools--> <!--【Tomcat线程池】--> <Executor name="tomcatThreadPool" namePrefix="catalin ...
Global site tag (gtag.js) - Google Analytics