日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

java杂乱

發(fā)布時(shí)間:2024/4/13 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java杂乱 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??

1 時(shí)間戳

long timeOfBefore=System.currentTimeMillis();try {Thread.sleep(5000);} catch (InterruptedException e) {e.printStackTrace();}long timeOfAfter=System.currentTimeMillis();System.out.println(timeOfAfter);System.out.println(timeOfBefore);System.out.println(timeOfAfter-timeOfBefore);

2 工具類以類名Utils結(jié)尾,且需要是final的,其中的方法必須是static的 3 四舍五入保留兩位小數(shù)

DecimalFormat df = new DecimalFormat("#.00"); return Double.valueOf(df.format(valueOfTps / constant)); or public static String saveTwoPoint(double d) {return savePoint(d, 2);}public static String savePoint(double d, int point) {return String.format("%.".concat(point + "f"), d);}
  • RunTime.getRunTime().addShutdownHook 這個(gè)方法的意思就是在jvm中增加一個(gè)關(guān)閉的鉤子,當(dāng)jvm關(guān)閉的時(shí)候,會(huì)執(zhí)行系統(tǒng)中已經(jīng)設(shè)置的所有通過方法addShutdownHook添加的鉤子,當(dāng)系統(tǒng)執(zhí)行完這些鉤子后,jvm才會(huì)關(guān)閉。所以這些鉤子可以在jvm關(guān)閉的時(shí)候進(jìn)行內(nèi)存清理、對(duì)象銷毀等操作。
  • public class TestShutdownHook {/*** @param args*/public static void main(String[] args) {// 定義線程1Thread thread1 = new Thread() {public void run() {System.out.println("thread1...");}};// 定義線程2Thread thread2 = new Thread() {public void run() {System.out.println("thread2...");}};// 定義關(guān)閉線程Thread shutdownThread = new Thread() {public void run() {System.out.println("shutdownThread...");}};// jvm關(guān)閉的時(shí)候先執(zhí)行該線程鉤子Runtime.getRuntime().addShutdownHook(shutdownThread);thread1.start();thread2.start();} }打印結(jié)果:thread2... thread1... shutdownThread...或者:thread2... thread1... shutdownThread...

    轉(zhuǎn)載于:https://my.oschina.net/112612/blog/1594970

    總結(jié)

    以上是生活随笔為你收集整理的java杂乱的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。