`
lijunaccp
  • 浏览: 160399 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
文章列表

数字签名

package com.test; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.security.Key; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import j ...

数字摘要(MD5)

package com.test; import java.security.MessageDigest; public class MD5 { /** * @param args */ public static void main(String[] args) throws Exception { String md5 = md5("测试数据"); System.out.println(md5); } public static String md5(String data) throws Exce ...
package com.test; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.security.Key; import java.security.KeyPair; import java.security.KeyPairGenerator; import jav ...
package com.test; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; impo ...

Cipher加密解密

package com.test; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; ...
package com.test; /** * 当每个线程中指定的KEY相同时, * 这些相同KEY的线程应每隔一秒依次输出时间值(互斥), * 如果KEY不同,则并行执行(相互之间不互斥) */ public class Test extends Thread { private TestDo testDo; private String key = "1"; private String value; public Test(String key,String key2,String value){ testD ...
package com.test; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.concurrent.CopyOnWriteArrayList; public class ThreadTest10 { /** * @param args */ public static void main(String[] args) { Collection users = /*new CopyO ...
所有集合都是线程不安全的,如果在多线程的情况下使用集合,就得考虑线程安全问题。 JDK5以上提供了线程安全的集合: 如: 使用Map map1 = Collections.synchronizedMap(map) 使用map同步。 还可以使用ConcurrentHashMap
package com.test; import java.util.Random; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class BlockingQueueTest { /** * @param args */ publ ...
package com.test; import java.util.Random; import java.util.concurrent.Exchanger; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ExchangerTest { /** * @param args */ public static void main(String[] args) { ExecutorService ...
package com.test; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class CountDownLatchTest { /** * @param args */ public static void main(String[] args) { final ...
package com.test; import java.util.Random; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class CyclicBarrierTest { /** * @param args */ public static void main(String[] args) { Executo ...
package com.test; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; public class SemaphoreTest { /** * @param args */ public static void main(String[] args) { ExecutorService ...
package com.test; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class ThreadTest9 { /** * @param args */ public static void main(String[] args) { final Utils9 ts = new Utils9(); ...

缓存类

package com.test; import java.util.HashMap; import java.util.Map; import java.util.concurrent.locks.ReentrantReadWriteLock; public class Cache { Map map = new HashMap(); ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); public Object get(String key){ lock.readLock() ...
Global site tag (gtag.js) - Google Analytics