- 博客(68)
- 资源 (4)
- 收藏
- 关注
原创 java 定时器
定时任务是我们在做项目的时候经常使用到的,比如定时发送心跳,定时请求数据等等。无论是使用开源的定时任务框架Quartz等,还是使用JDK原生态的定时任务都可以很好的完成这个任务。碰巧最近看源码看到了有的地方使用到了javax.management.timer.Timer,所以在这里记录下JDK中提供的几种定时任务的使用方法,权当做总结了~1、javax.management.timer.Timer对
2015-08-04 01:17:13
596
原创 java jdk TimSort
在jdk1.6的时候,java默认使用的排序算法是mergesort。 public static <T> void sort(T[] a, Comparator<? super T> c) { T[] aux = (T[])a.clone(); if (c==null) mergeSort(aux, a, 0, a.length, 0);
2015-08-02 10:43:51
1557
原创 java Enum
在项目中经常使用Enum,我们知道Enum类型只能使用已经定义好的Enum类型,不能对Enum进行实例化。但是从来没有考虑过java是如何实现这个类型的。今天同事问了这个问题,借此机会正好看看。首先定义Enum类型,public enum EnumTest { enum1(1, 1), enum2(2, 2); private int i; private int j;
2015-07-30 00:12:31
775
原创 整齐打印-DP
考虑在一个打印机上整齐地打印一段文章的问题。输入的正文是n个长度分别为L1、L2、……、Ln(以字符个数度量)的单词构成的序列。我们希望将这个段落在一些行上整齐地打印出来,每行至多M个字符。“整齐度”的标准如下:如果某一行包含从i到j的单词(i
2015-07-28 22:13:09
874
原创 Metaspace
简介从JDK8开始,永久代(PermGen)的概念被废弃掉了,取而代之的是一个称为Metaspace的存储空间。Metaspace使用的是本地内存,而不是堆内存,也就是说在默认情况下Metaspace的大小只与本地内存大小有关。当然你也可以通过以下的几个参数对Metaspace进行控制:-XX:MetaspaceSize=N 这个参数是初始化的Metaspace大小,该值越大触发Metaspac
2015-07-05 18:16:30
8345
原创 STM
STM全称是soft transaction memory,是并发编成的模型之一。与传统的基于锁的并发模型不同的地方是,STM各个线程都是相互独立的,它假设各个线程不受其他线程的影响,也就是各个线程在访问并发区域的时候互不干扰,可以实现高效的并发。问题来了,在java中各个线程都有自己的一份独立副本,在线程中进行操作的时候首先访问副本数据,当线程结束时将副本重新写入到主存中,为了保证线程之间并发安
2015-03-23 22:48:54
1140
原创 Akka【八】 Vector Clock在AKKA中的实现
/** * Copyright (C) 2009-2014 Typesafe Inc. */package akka.clusterimport akka.AkkaExceptionimport System.{ currentTimeMillis ⇒ newTimestamp }import java.security.MessageDigestimport java.ut
2014-10-06 00:27:56
764
原创 Cristian’s (Time Server) Algorithm
在集群中事件的先后顺序可以通过时间戳来进行定义。在自然状态下,大家都会想到使用物理时钟来表示时间戳,然而当系统对事件的时间有严格的要求的时候(比如状态的同步),物理时钟存在如下问题:由于服务器之间存在的结构差异,导致服务器运行一段时间后产生不同的时间飘移,这样不同的服务器的物理时钟存在一定的差异。直接导致了,事件A发生的顺序可能晚于事件B,但是发送过来的时间戳确小于B,如果涉及到状态的同步B的
2014-09-02 23:41:11
3721
转载 Synchronization in a Distributed System
Synchronization in a Distributed SystemRylan Dirksen 04 Oct 2013 ToolsMost of us use distributed systems on a daily basis, and for good reason; the stability, fault tolerance and scalabi
2014-08-30 09:02:34
947
转载 Why Vector Clocks Are Hard
April 5, 2010A couple of months ago, Bryan wrote about vector clocks on this blog. The title of the post was “Why Vector Clocks are Easy”; anyone who read the post would realize that he meant that
2014-08-29 15:18:49
634
转载 Why Vector Clocks are Easy
January 29, 2010Vector clocks are confusing the first time you’re introduced to them. It’s not clear what their benefits are, nor how it is you derive said benefits. Indeed, each Riak developer has
2014-08-29 14:24:30
722
原创 Akka 【五】 Example Of Handling Fault
/** * Copyright (C) 2009-2014 Typesafe Inc. */package docs.actor.japi;//#all//#importsimport java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import
2014-07-20 18:00:01
1170
转载 Micro Service Architecture
原文链接Micro Service ArchitectureMicro Service Architecture is an architectural concept that aims to decouple a solution by decomposing functionality into discrete services. Think of it as applyi
2014-07-17 11:49:49
2777
原创 ProxyGenerator
/* * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or
2014-06-25 21:03:45
2116
原创 Spin Lock -- Anderson’s Algorithm
Anderson’s Algorithm基于队列实现,也就是基于数组的算法。
2014-06-04 16:53:20
1130
原创 Jetty学习 【九】 修改jetty.xml为服务器添加功能
jetty.xml用于配置服务器Server。默认的情况下,配置了线程池,connector,还有处理请求的handler。
2014-06-02 23:20:49
1577
转载 Java Objects Memory Structure
原文地址Java Objects Memory StructureUpdate (December 18th, 2008): I've posted here an experimental library that implements Sizeof for Java.One thing about Java that has always bothered me,
2014-05-29 19:44:34
882
转载 Java ByteCode Part 2
yuanUnderstanding how Java code is compiled into byte code and executed on a Java Virtual Machine (JVM) is critical because it helps you understand what is happening as your program executes. This
2014-05-29 15:44:15
709
转载 Java ByteCode Part 1
Understanding how Java code is compiled into byte code and executed on a Java Virtual Machine (JVM) is critical because it helps you understand what is happening as your program executes. This underst
2014-05-29 15:35:14
991
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人