自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(78)
  • 收藏
  • 关注

原创 【代码积累】URLConnection test

import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.util.Calendar;import net.sf.json

2017-06-16 13:24:58 321

原创 【代码积累】UDP server

import java.io.IOException;import java.net.*;public class UDPServer { public static final int LocalPort = 3000; public static final int RemotePort = 9000; public static void main(String[] arg

2017-06-16 13:23:47 630

原创 【代码积累】UDP client

import java.io.IOException;import java.net.DatagramPacket;import java.net.DatagramSocket;import java.net.InetAddress;import java.net.SocketException;import java.net.UnknownHostException;public

2017-06-15 13:30:07 732

原创 【代码积累】ThreadLocal

public class Test { public void test() { ThreadId id = new ThreadId(); TaskFac fac = new TaskFac(); for( int i=0; i< 10; i++ ) { fac.createTask().start(); try { Thread.sleep(100);

2017-06-15 13:28:14 229

原创 【代码积累】TCP server

import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import

2017-06-15 13:23:24 297

原创 【代码积累】TCP client

import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.Inet4Address;import java.net.InetAddress;import java.net.InetSocketAddress;import java.net.Socke

2017-06-15 13:22:29 312

原创 【代码积累】Simulate schedule service

import java.util.Collections;public class Test { public void test() { SScheduleExecutor scheduledThreadpool = new SScheduleExecutor(); System.out.println("Main test:time stamp = "+System.curre

2017-06-15 13:20:57 251

原创 【代码积累】SelectionSort

public class main { public static void main(String[] args) { // TODO Auto-generated method stub int[] test = {5,4,3,2,1}; selectionSort(test); for(int i=0;i<test.length;i++) { System.o

2017-06-15 13:18:09 261

原创 【代码积累】ScheduledAtFixRate test

import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.TimeUnit;public class Test { p

2017-06-15 13:17:03 462

原创 【代码积累】replace constructor with factory

import java.util.concurrent.ConcurrentHashMap;public class Factory { private ConcurrentHashMap registedList = new ConcurrentHashMap(); public void register(String name,Object object) { registed

2017-06-15 13:14:57 224

原创 【代码积累】replace constructor with factory method

import java.lang.reflect.InvocationTargetException;/*典型的遵循OCP原则的编程技巧,结合了继承,反射; * 适用于需要大量创建同一族对象的场合,即,这些对象有共同的父类,但是各自类型不同; * 通常情况下,如果使用子类的构造器构造,需要在create方法中放置一个switch结构,当需要增加子类类型时,不便于扩展; * 使用反射,则只需

2017-06-15 13:13:42 237

原创 【代码积累】reflection study

import java.lang.reflect.*;import java.util.Map;public class Test { public String name = null; private int cnt = 1; public void setCnt(int cnt) { this.cnt = cnt; } public Test() {

2017-06-15 13:12:26 185

原创 【代码积累】quick sort bia direction

public class Main { public static void main(String[] args) { // TODO Auto-generated method stub //int[] test = {5,4,3,2,1}; int[] test={49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,56,1

2017-06-15 13:11:11 257

原创 【代码积累】quick sort

import java.awt.image.PixelInterleavedSampleModel;public class Main { public static void main(String[] args) { // TODO Auto-generated method stub //int[] test = {5,4,3,2,1}; int[] test={49,

2017-06-15 13:10:15 202

原创 【代码积累】NIO server

import java.io.IOException;import java.net.InetAddress;import java.net.InetSocketAddress;import java.net.UnknownHostException;import java.nio.ByteBuffer;import java.nio.channels.ClosedChannelExce

2017-06-15 13:08:40 203

原创 【代码积累】NIO client

import java.io.IOException;import java.net.InetAddress;import java.net.InetSocketAddress;import java.net.UnknownHostException;import java.nio.ByteBuffer;import java.nio.channels.SelectionKey;imp

2017-06-15 13:07:35 223

原创 【代码积累】JVM shutdown hook

import org.omg.SendingContext.RunTime;public class Main extends Thread{ private volatile boolean isExit = false; private volatile static boolean isRefresh = false; private static Main mainserver

2017-06-15 13:06:00 219

原创 【代码积累】join a thread

public class Test { public void test() { Thread subTask = new Thread(new showTask()); /*使用了join,则主线程的打印必然在子线程之后*/// try {// subTask.start();// subTask.join();// System.out.println(

2017-06-15 13:04:45 183

原创 【代码积累】IntegerObjectCompare

/*Study autoBoxing and unboxing; * Object compare in JAVA*/public class Test { public class Value { public int i; // public int hashCode() // { // return i; // } p

2017-06-15 13:03:21 214

原创 【代码积累】InsertionSort via list

import java.util.Arrays;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.ListIterator;public class Test { public void test() { //int[] test = {5,

2017-06-15 13:02:05 193

原创 【代码积累】InsertionSort

public class Main { public static void main(String[] args) { // TODO Auto-generated method stub //int[] test = {5,4,3,2,1}; //int test[] = {5,4,3,2,1}; 两种写法都可以,建议使用上一种写法 int[] test={49,38,65

2017-06-15 13:00:43 183

原创 【代码积累】FutureTask

import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.Fu

2017-06-15 12:57:13 130

原创 【代码积累】ForkJoin sum the array

import java.util.concurrent.ForkJoinPool;/*计算一千万个整数的累加值,一种采用fork/join,另外一种采用直接计算。 * 根据预算结果,发现SumTask的fork任务的阈值选择对并行算法的效率影响很大。 * 当阈值设为50,并行算法的耗时几乎是常规算法的10倍; * 当阈值设为500000,并行算法的耗时是常规算法的一半。 * 综上,并行算

2017-06-14 14:17:49 159

原创 【代码积累】FlexibleIterator

import java.util.Iterator;import java.util.LinkedList;import java.util.List;public class FlexibleIterator { public static void main(String[] args) { // TODO Auto-generated method stub List

2017-06-14 14:12:23 480

原创 【代码积累】factory pattern without reflection

public class FactoryWithoutReflection { public static void main(String[] args) { // TODO Auto-generated method stub Car car = null; Plane plane = null; Car.register2Factory(); Plane.reg

2017-06-14 13:59:46 197

原创 【代码积累】Event handling framrwork

import java.util.LinkedList;import java.util.List;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.

2017-06-14 13:58:10 185

原创 【代码积累】Enum

public class Test { public void test() { String currentType = ConnectionType.Zondy.getType(); System.out.println("ConnectionType = "+currentType); } public enum ConnectionType { /*These a

2017-06-14 13:56:58 162

原创 【代码积累】Date split

import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.Iterator;import java.util.List;public class Test { public void test() { /*指定一个日期,获取其UTC时间,然后通过显示

2017-06-14 13:55:58 774

原创 【代码积累】semaphore

import java.util.concurrent.LinkedBlockingQueue;import java.util.concurrent.Semaphore;public class OperationQueue { private LinkedBlockingQueue queue = null; private Semaphore semaphore = new Se

2017-06-14 13:54:02 139

原创 【代码积累】countdown latch

import java.util.concurrent.atomic.AtomicInteger;import java.util.concurrent.locks.Condition;import java.util.concurrent.locks.ReentrantLock;public class CustomLinkedBlockingQueue implements Cust

2017-06-14 13:52:45 311

原创 【代码积累】condition of lock

import java.util.concurrent.atomic.AtomicInteger;import java.util.concurrent.locks.Condition;import java.util.concurrent.locks.ReentrantLock;public class CustomLinkedBlockingQueue implements Cust

2017-06-14 13:50:15 178

原创 【代码积累-4】cal MD5

import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;//import org.apache.commons.codec.binary.Hex;public class CalMD5_Test { public static void main(String[] args) {

2017-06-10 13:15:59 1143

原创 【代码积累-3】bubble sort

public class Test { public void test() { int test[] = {49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,101,56,17,18,23,34,15,35,25,53,51}; //int test[] = {5,4,3,2,1}; Bubble bubble = new

2017-06-10 13:12:35 151

原创 【代码积累-2】binary search

import java.util.Arrays;public class Test { int test[] = {49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,101,56,17,18,23,34,15,35,25,53,51,111,222,333,444,546,768}; public void test() {

2017-06-10 13:10:29 148

原创 【代码积累-1】ActiveObject

import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util.concurrent.Future;import java.util.concurrent.FutureTask;import java.util.concurrent.LinkedBloc

2017-06-10 13:07:46 141

原创 [JAVA学习笔记-97]ActiveObject模式的Scheduler的关键实现

public class CustomScheduler implements Runnable { private LinkedBlockingQueue activationQueue = new LinkedBlockingQueue(); @Override public void run() { dispatch(); } public Future

2017-06-10 12:42:16 159

原创 [JAVA学习笔记-96]ThreadLocal

综述:ThreadLocal可以理解为一个对象容器,这个容器为每个访问该容器的线程,封装了一个只对当前线程可见的对象。也就是说,当多个线程共用一段代码时(例如同一个runnable对象分配给多个线程运行),ThreadLocal封装的对象将会是线程安全的,只是访问的时候,需要用到set、get、remove、initValue等方法,否则,这些对象将会是多线程共享的,是非线程安全的

2017-06-10 12:39:43 190

原创 [JAVA学习笔记-95]REST框架浅析

基于Web的架构,实际上就是各种规范的集合,这些规范共同组成了Web架构。比如Http协议,比如客户端服务器模式,这些都是规范。每当我们在原有规范的基础上增加新的规范,就会形成新的架构。而REST正是这样一种架构,他结合了一系列的规范,而形成了一种新的基于Web的架构风格。传统的Web应用大都是B/S架构,它包括了如下一些规范:1.客户-服务器:2.无状态性:要求通信必须在

2017-06-10 12:37:05 211

原创 [JAVA学习笔记-94]JVM的client与server模式

client模式在 64-bit JDK上已经被忽略了,直接使用Java Hotspot Server VM.出处:https://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html-clientSelects the Java HotSpot Client VM. A 64-bit capable JDK

2017-06-10 12:35:29 200

原创 [JAVA学习笔记-93]DatagramSocket的线程安全性

1.DatagramSocket reads and writes are independent of each other2.DatagramSocket writes are atomic so they are thread-safe3.DatagramSocket reads are synchronized by java and they are also atomic at

2017-06-10 12:28:50 317

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除