java tips
Posted dayspring
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java tips相关的知识,希望对你有一定的参考价值。
getWriter() has already been called for this response
reason: getWriter和getOutputStream(chain.doFilter(request, response);) 二者只能选其一,调用了其中一个就不能调用另一个了
3 ways to cut out a string
- split(using RegEx, not KMP string matching arithmetic, splite one time)
- StringTokenizer(not recommended by jdk, just a legacy class, be retained for compatibility reason, split in turn)
- substring
java中获取比毫秒更为精确的时间
System.currentTimeMillis() 的文档,原来这个方法调用了个native方法,获取的时间精度会依赖于操作系统的实现机制
在Java中可以通过System.currentTimeMillis()或者System.nanoTime() (JDK>=5.0) 方法获得当前的时间的精确值。但是通过阅读Javadoc,我们发现这两个方法并不一定保证得到你所期望的精度。先来看System.currentTimeMillis():
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
如何在windows上实现精确的毫秒计时呢。答案就是用“System.nanoTime()/1000000L”代替“System.currentTimeInMills()”
http://blog.csdn.net/paul_lh/article/details/6419982
秒的换算:ms(毫秒),μs(微秒),ns(纳秒),ps(皮秒)
SimpleDateFormat && Calendar is not thread safe
以上是关于java tips的主要内容,如果未能解决你的问题,请参考以下文章