fxleyu / cu-cafes Goto Github PK
View Code? Open in Web Editor NEWThis is a repository of Java. And CU is a cafes unders downstairs.
This is a repository of Java. And CU is a cafes unders downstairs.
背景:
ordinal()
和 顺序调整
Java 虚拟机给每条线程分配独立的 JVM 栈空间以免彼此干扰。独立的栈使得线程可以追踪它们自己下一条要执行的指令,这些指令会依线程不同而有所区别。栈空间也为每条线程单独准备了一份方法参数、局部变量以及返回值的拷贝。
Thread
和 Runnable
业务代码中大量这类似于如下的代码
if (shouldDoSomething()) {
sirector.start(event);
do = true;
}
<Effective Java 中文版 第2版>
ActiveMQ是一个MOM,具体来说是一个实现JMS规范的系统间远程通信的消息代理。
允许多个任务同时下载,但最多同时下载5个。
简单集中排序
Guava实现了一种特殊的数据结构BiMap
,可以成为双向map,这种特殊的map既实现了key到value的映射,同时实现了value到key的映射。
SOA 是一种体系架构方法,用于定义、链接和集成具有清晰边界且功能方面自包含的可重用业务服务。在这种类型的体系架构中,您可以对业务流程中的业务服务进行协调。
SOA is an architecture approach for defining, linking, and integrating reusable business services that have clear boundaries and are self-contained with their own functionalities.
https://www.ibm.com/developerworks/cn/education/webservices/ws-soa-ibmcertified/index.html
null
null
数组或列表equals()
(T... all)
签名在处理多语言下的项目时(尤其是移动端),有时需要根据系统语言环境做特殊化定制。
所以,就需要使用到 java.util.Locale
类的实例对象。
而该对象中主要使用其语言码和国家码。
但对于语言码和国家码集合不太了解,这里希望对其有一个深入的感官。
本部分的源码均来自于 JDK 1.6
线程(Thread)机制允许同时进行多个活动。
本章阐述的建议可以帮助你编写出清晰、正确、文档组织良好的并发程序。
JMS的API是一个Java面向消息中间件(Message-oriented middleware, MOM)的,为了在两个或多个Client之间发送消息的API。它是一个处理生产者-消费者问题( Producer-consumer problem)的实现。JMS是Java EE平台的一部分。JMS也是一个在JCP(Java Community Process)开发的一种规范,被称为JSR 914。它是一个允许应用组件间基于Java EE去创建、发送、接收和阅读消息。JMS允许分布式应用程序的不同组件之间的通信是松耦合的、可靠的和异步的。
其中MOM是面向消息中间件,是用于以分布式应用或系统中的异步、松耦合、可靠、可扩展和安全通讯的一类软件。MOM的总体**是它作为消息的发送器和消息接收器之间的消息中介,这种中介提供了一个全新水平的松耦合。
JMS API 提供了两种模式:
文章章节
Discards the least recently used items first. This algorithm requires keeping track of what was used when, which is expensive if one wants to make sure the algorithm always discards the least recently used item. General implementations of this technique require keeping "age bits" for cache-lines and track the "Least Recently Used" cache-line based on age-bits.
在JDK中有一个实现,它就是 LinkedHashMap
,它使用链表和HashMap来实现了。
Java 编程语言使用异常去处理错误或者异常事件。
try-with-resource
预计Java 平台在设计之初就支持并发编程。
等同与 #44 。
在最近的迭代需求过程中,组内出现了很多问题。先是,上线后引起线上故障导致回滚;后是,需求未在迭代周期内上线,导致上线延迟。为此,部门 Leader 要求所有需求必须要有 Use Case 编写。此外还涉及到业务规则、流程图、异常流等。
服务进行压测,发现其 max 时间远大于设置的读超时时间,感觉很疑惑。
疑惑原因为,如果出现读超时,这边很快捕获到超时异常,中断等待,不会出现 max 太长的情况。
volatile
关键字jstack
jstat
jmap
jmap -histo
jmap -heap
jmap -dump
今天Review代码时,发现Android代码一个奇怪的现象。
就是在匿名内部类中直接调用外部类的实例方法。
在我的印象中,调用一个方法等同于在这个方法前直接加this
,而这个this
是内部类的实例。
按这个逻辑,在匿名内部类中直接调用外部类的实例方法在编译时是直接报错的。
但实际编译这个模块,并没有出问题。看运行时log一切正常。
故,写了一个简单的Demo来验证之前的观念是错误的。代码如下:
public class InnerClass {
public static void main(String[] args) {
new InnerClass().process();
}
public void process() {
new Thread() {
@Override
public void run() {
System.out.println(toString("test"));
}
}.start();
}
public String toString(String string) {
return string;
}
}
但实际结果证实了我的观念在官方JDK中是没有问题的,但在OpenJDK中就有了问题。
在官方JDK中没有问题,所以上述代码编译失败,结果如下:
在OpenJDK中,我的观念就有问题了,上述代码直接编译成功了,结果如下:
那么问题来了,OpenJDK相对于官方JDK有什么不同?
我可以在哪里找到文档来查看这些不同?
我努力过,但没有得到明确的答案。
@NotNull
和 @Nullable
;在最近的迭代需求过程中,组内出现了很多问题。先是,上线后引起线上故障导致回滚;后是,需求未在迭代周期内上线,导致上线延迟。为此,部门 Leader 要求所有需求必须要有 Use Case 编写。
==
vs. equals(var)
同一对象 vs 判等
char[]
vs String
char[]
更好。可以在使用之后动态更改数据。
字符串是否使用switch条件语句?
JDK 7.0 及以上可以
如何将字符串转化为 int
int n = Integer.parseInt("10")
使用空白字符分割字符
String[] strArray = aString.split("\\s+");
substring() 方法
String vs StringBuilder vs StringBuffer
重复一个字符串
String str = "123";
String repeated = StringUtils.repeat(str, 3);
String str = "Sep 17, 2013";
Date date = new SimpleDateFormat("MMMM d, yy", Locale.ENGLISH).parse(str);
int n = StringUtils.countMatches("1111222", "1");
代码如下:
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
Date sDt3 = sf.parse(str3);
Date sDt4 = sf.parse(str4);
long ld3 = sDt3.getTime() /1000;
long ld4 = sDt4.getTime() /1000;
System.out.println(ld4-ld3);
}
输出结果如下
353
版本信息:
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Dynamic Code Evolution Client VM (build 0.2-b02-internal, 19.0-b04-internal, mixed mode)
Timezone(`TimeZone.getDefault()`):
sun.util.calendar.ZoneInfo[id="Asia/Shanghai",
offset=28800000,dstSavings=0,
useDaylight=false,
transitions=19,
lastRule=null]
Locale(Locale.getDefault()): zh_CN
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.