上一页 1 2 3 4 5 6 7 8 9 10 ··· 24 下一页
摘要: 1 互斥是指某一资源同时只允许一个访问者对其进行访问,具有唯一性和排它性。但互斥无法限制访问者对资源的访问顺序,即访问是无序的。 2 同步是指在互斥的基础上(大多数情况),通过其它机制实现访问者对资源的有序访问。 3 同步其实已经实现了互斥,所以同步是一种更为复杂的互斥。 4 互斥是一种特殊的同步。 阅读全文
posted @ 2019-11-09 09:43 踏月而来 阅读(1843) 评论(0) 推荐(0) 编辑
摘要: AtomicInteger可以保证原子性,可见性,有序性 public class AtomicIntegerTest { private static AtomicInteger value = new AtomicInteger(); public static void main(String 阅读全文
posted @ 2019-11-08 21:39 踏月而来 阅读(341) 评论(0) 推荐(0) 编辑
摘要: (1)手动加载mysql驱动实现类 1 Class<?> forName = Class.forName("com.mysql.jdbc.Driver"); 这时加载mysql实现类的是系统类加载器,执行上面的语句会将自己注册到DriverManager中的registeredDrivers。 2 阅读全文
posted @ 2019-11-08 17:19 踏月而来 阅读(605) 评论(0) 推荐(0) 编辑
摘要: 二叉树按层遍历 public class WideFirstSearch { public static void main(String[] args) { Node root = new Node("A"); root.left = new Node("B"); root.right = new 阅读全文
posted @ 2019-11-07 11:32 踏月而来 阅读(300) 评论(0) 推荐(0) 编辑
摘要: /** * 深度遍历的一个简单例子 * */ public class EmployeeImportance { private static int res = 0; private static Employee employee; public static void main(String[ 阅读全文
posted @ 2019-11-07 10:59 踏月而来 阅读(162) 评论(0) 推荐(0) 编辑
摘要: /** * 一个数组,一半奇数,一半是偶数,要将数组按照偶奇偶奇的顺序排序 * 思路,找出下标是偶数但值是奇数的,和下标是奇数但值是偶数的,两个互换,直到结束 */ public class SortArrayByParityll { public static void main(String[] 阅读全文
posted @ 2019-11-06 15:48 踏月而来 阅读(1083) 评论(0) 推荐(0) 编辑
摘要: /** * 使用两个指针i和j,初始化均为0。然后j往后遍历,若遇到了奇数,则将 A[j] 和 A[i] 交换位置,同时i自增1,这样操作下来,同样可以将所有的偶数都放在奇数前面 * */ public class SortArrayByParity { public static void mai 阅读全文
posted @ 2019-11-06 14:47 踏月而来 阅读(1242) 评论(0) 推荐(0) 编辑
摘要: 动态规划 /** * 硬币找零, 假如你的硬币面值有1,2,5等,每种面值的都有无数个,求找零100最少要多少个硬币 * */ public class CoinChange { public static void main(String[] args) { int [] coins = new 阅读全文
posted @ 2019-11-06 12:10 踏月而来 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Balking模式讲的是如果现在不合适执行这个操作,或者没必要执行这个操作,就停止处理,直接返回 自动保存功能的实现逻辑一般都是隔一定时间自动执行存盘操作,存盘操作的前提是文件做过修改,如果文件没有执行过修改操作,就需要快速放弃存盘操作 单次初始化 阅读全文
posted @ 2019-11-01 22:28 踏月而来 阅读(267) 评论(0) 推荐(0) 编辑
摘要: //设计为单例 public final class ActionContext { // 构造方法私有化 private ActionContext() { } // Holder类 private static class ContextHolder { private final static ActionContext actionContext = new ActionContext() 阅读全文
posted @ 2019-11-01 20:34 踏月而来 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Guarded Suspension 设计模式可以保证,当线程在访问某个对象时,发现条件不满足,就挂起等待条件满足时再次访问 public class GuardedSuspensionQueue { // 定义存放Integer类型的queue private final LinkedList queue = new LinkedList(); // 定义q... 阅读全文
posted @ 2019-11-01 17:40 踏月而来 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 不可变对象需要满足的条件 1 对象创建以后其状态就不能修改 2 对象所有域都是final类型 (这样只能对每个域赋值一次,通过构造器初始化所有成员,进行深度拷贝,在get方法中不直接返回对象本身,而是克隆对象并返回克隆) 3 对象是正确创建的(在对象创建期间,this引用没有逸出) 阅读全文
posted @ 2019-10-30 17:16 踏月而来 阅读(587) 评论(0) 推荐(0) 编辑
摘要: /** * ReentrantLock是独占锁 * Lock锁的使用,把锁和要用锁同步的代码放在一起,这里就是放在Printer类中了 * 获取到锁后,最后要在finally代码块中手动释放锁 */ public class LockTest { public static void main(String[] args) { Printer p... 阅读全文
posted @ 2019-10-30 16:11 踏月而来 阅读(1439) 评论(0) 推荐(0) 编辑
摘要: /*** * 三个线程读数据,三个线程写数据 * */ public class ReadWriteLockTest { public static void main(String[] args) { final ReadWrite rw = new ReadWrite(); for (int i = 0; i < 3; i++) { ... 阅读全文
posted @ 2019-10-30 14:42 踏月而来 阅读(246) 评论(0) 推荐(0) 编辑
摘要: public class ReentrantReadWriteLockTest { public static void main(String[] args) throws InterruptedException { // testReenter(); // testUpgrade(); testDowngrade(); } /** * 在同一个线程中,在没有释放写锁的情况下,就去申请读锁,这 阅读全文
posted @ 2019-10-30 12:26 踏月而来 阅读(958) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 24 下一页