Skip to content

Instantly share code, notes, and snippets.

Avatar
😀

yanglikun yanglikun

😀
View GitHub Profile
View BiasedLockAndHashCodeTest.java
/**
* 使用如下命令运行:
* java -XX:+UseBiasedLocking //开启偏向锁,如果关闭用 -XX:-UseBiasedLocking
* -XX:+UnlockDiagnosticVMOptions //打开诊断模式,才能使用PrintBiasedLockingStatistics打印偏向锁信息
* -XX:+PrintBiasedLockingStatistics//在C1中打印偏向锁信息
* -XX:TieredStopAtLevel=1 //设置JIT编译器为C1
* -XX:BiasedLockingStartupDelay=0 //关闭偏向锁启动延时,jdk6有4秒延时,4秒内用lightweight,4秒后才开始启动biased lock
* BiasedLockAndHashCodeTest
*/
public class BiasedLockAndHashCodeTest {
View ObjectHeader32.txt
|----------------------------------------------------------------------------------------|--------------------|
| Object Header (64 bits) | State |
|-------------------------------------------------------|--------------------------------|--------------------|
| Mark Word (32 bits) | Klass Word (32 bits) | |
|-------------------------------------------------------|--------------------------------|--------------------|
| identity_hashcode:25 | age:4 | biased_lock:1 | lock:2 | OOP to metadata object | Normal |
|-------------------------------------------------------|--------------------------------|--------------------|
| thread:23 | epoch:2 | age:4 | biased_lock:1 | lock:2 | OOP to metadata object | Biased |
|-------------------------------------------------------|--------------------------------|--------------------|
|
View gist:b4741b98237c117eba609fb08d673f68
pragma solidity ^0.4.0;
contract Counter{
uint public count=10;
function inc(uint num) public returns (uint){
return count+=num;
}
}
contract CallCounter{
uint public count=20;
function callByAddr(address addr) public returns(uint){
View freemarker 静态类调用
public class FreemarkerModelInterceptor implements HandlerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(FreemarkerModelInterceptor.class);
private Map<String, String> utilClasses;
private TemplateHashModel staticModels;
public FreemarkerModelInterceptor() {
BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_26);
View genericExtendAndSuper.java
List<? extends Number> extendsList = null;
List<? super Number> superList = null;
List<Object> objList = null;
List<Number> numberList = null;
List<Integer> integerList = null;
//extendsList=objList; //compile error
extendsList = numberList;
extendsList = integerList;
@yanglikun
yanglikun / genericRunTimeError.java
Created Sep 2, 2017
编译没错,运行时出错。和泛型有关
View genericRunTimeError.java
class A<T extends Comparable & List> {
public void test(T t) {
t.add("cc");
}
}
public class Test {
public static void main(String[] args) {
@yanglikun
yanglikun / Suppliers.memoizeWithExpiration
Created Aug 29, 2017
Suppliers.memoizeWithExpiration
View Suppliers.memoizeWithExpiration
DateTime dateTime = DateTime.now().plusSeconds(2);
Supplier<String> supplier = Suppliers.memoizeWithExpiration(() -> {
DateTime now = DateTime.now();
if (now.getSecondOfDay() == dateTime.getSecondOfDay()) {
throw new RuntimeException("haha~~" + now.toString("yyyy-MM-hh HH:mm:ss"));
}
return "time:" + now.toString("yyy-MM-dd HH:mm:ss");
}, 1, TimeUnit.SECONDS);
for (int i = 0; i < 10; i++) {
try {
View JD_PLT_EXT__idea_inspections.xml
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="JD_PLT_EXT" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="MissortedModifiers" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_requireAnnotationsFirst" value="true" />
</inspection_tool>
View JD_PLT_EXT_idea_codeStyle.xml
<code_scheme name="JD_PLT_EXT_codeStyle">
<option name="LINE_SEPARATOR" value="&#xA;" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />