martes, junio 26, 2012

Bye, Bye, 5 * 60 * 1000 //Five Minutes, Bye, Bye


Llueve, llueve, y mientras nos mojamos como tontos. LLueve, llueve, y en un simple charco a veces nos ahogamos. (Llueve - Melendi)

In this post I am going to talk about one class that was first introduced in version 1.5, that I have used too much but talking with some people they said that they didn't know it exists. This class is TimeUnit.

TimeUnit class represents time durations at a given unit of granularity and also provides utility methods to convert to different units, and methods to perform timing delays.

TimeUnit is an enum with seven levels of granularity: DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS and SECONDS.

The first feature that I find useful is the convert method. With this method you can say good bye to typical:

     private static final int FIVE_SECONDS_IN_MILLIS = 1000 * 5;

to something like:

     long duration = TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS);

But also equivalent operations in a better readable method exist. For example the same conversion could be expressed as:

     long duration = TimeUnit.SECONDS.toMillis(5);

The second really useful sets of operations are those related with stopping current thread.

For example you can sleep current thread with method:

     TimeUnit.MINUTES.sleep(5);

instead of:

     Thread.sleep(5*60*1000);

But you can also use it with join and wait with timeout.

     Thread t = new Thread();
     TimeUnit.SECONDS.timedJoin(t, 5);

So as we can see TimeUnit class is though in terms of expressiveness, you can do the same as you do previously but in a more fashionable way. Notice that you can also use static import and code will be even more readable.

Keep Learning,

18 comentarios:

Anónimo dijo...

Thanks for the tip :-) Didn't know about TimeUnit.

Alternatively you could use the constants from Commons lang:

long delay = 5 * MILLIS_PER_MINUTE;

Alex Soto dijo...

Hi Arend thank you very much for reading my blog. I didn't know commons lang has this constants, thanks for the comment. The only disadvantage that I see is that you add a new dependency to your project.

Thanks for the comment,
Alex.

JUAL OBAT ABORSI TANGERANG dijo...


This blog is a great source of information which is very useful for me.

Jual Obat Aborsi Pekanbaru

Jual Obat Aborsi Bekasi

Jual Obat Aborsi malang

Jual Obat Aborsi

Obat Aborsi semarang

Obat Aborsi yogyakarta

Obat Aborsi solo

Obat Aborsi

-Can be very slow but shows all backlinks along with their PR, Anchor and if it's a Nofollow

ikut numpan gan dijo...

Jual Cytotec Obat Aborsi Asli Obat Penggugur Kandungan & Janin
jual obat aborsi kandungan

Jual Obat Aborsi, Obat Penggugur Kandungan Aman, Jual Obat Aborsi Tuntas, Jual Obat Aborsi Ampuh

Jual Obat Aborsi Asli Ampuh, Obat Penggugur Kandungan Ampuh

Obat Aborsi, Obat Aborsi Manjur, Obat Penggugur Kandungan, Jual Obat Aborsi Ampuh

Obat Aborsi, Obat Aborsi Aman, Jual Obat Aborsi Cytotec Asli

Jual Obat Aborsi Cytotec
Obat Aborsi
Obat Penggugur Kandungan
Cara MenggugurKan Kandungan Janin

Satuperjuangan dijo...

Excellent post. I used to be checking continuously this blog and I’m impressed!
Very helpful info particularly the ultimate part Obat Jantung Tradisional
care for such information much. I used to be seeking this
particular info for a long time.

Agen Vimax Asli Lampung dijo...

Permisi Numpang Lapaknya BlogWalking...???
Semoga BlogWalking Ini Sangat Bermanfaat.....

Hammer Of Thor
Vimax Asli Makassar
Jual Blue Wizard di Lampung
Jual Hammer Of Thor di Lampung
Jual Obat Kuat Viagra di Lampung
Jual Hammer Of Thor di Makassar
Jual Vacum Penis di Lampung
Jual KLG Pil di Lampung
jual Obat Kuat Viagra di Makassar
Jual Potenzol di Lampung

>>>>>Info Pemesanan<<<<<<
...>>>Cllg/Sms.081226266667
...>>>BBM.27FDf727

Resty Ananta dijo...

Excuse Numpang Lapak his Blog walking may be useful with blog walking here Can Learning New Thank You .... !!!!
- Obat pembesar penis
- Obat Pembesar Penis asli
- hammer of thor asli
- Obat Hammer Of Thor di Makassar
- Obat hammer of thor di lampung
- Obat hammer of thor di Medan
- Obat hammer of thor di palembang
- Obat hammer of thor di pekanbaru
- Obat hammer of thor di bali
- hammer of thor di denpasar
- hammer of thor di surabaya
- hammer of thor di jakarta
- Obat Hammer Of Thor di bogor
- Obat hammer of thor di semarang
- Obat hammer of thor di jambi
- Obat pembesar penis di gorontalo
- Obat hammer of thor di gorontalo
- hammer of thor di lampung
- hammer of thor di bali
- Obat hammer of thor di denpasar
- Obat Pembesar Penis di Makassar
- Obat Vimax Pembesar Penis di Lampung
- Hammer Of Thor di Makassar
- Obat pembesar penis di palembang
- Obat Kuat asli
- Obat Kuat di Makassar
- Obat kuat di lampung
- Obat kuat di medan
- Alat vacum Penis di bali
- Obat pembesar penis original
- obat penirum asli
- Obat kuat di medan
- hammer of thor


>>>>Kontak Respons<<<<
....Cllg/Sms.085803373822
....Pin Blackberry. DACF0162
....Whatsap. 082223570785

jual obat aborsi bekasi dijo...

This blog is a great source of information which is very useful for me.

Jual Obat Aborsi Malang Dalam 3 jam Tuntas Hub: 081226652077

Jual Obat Aborsi Bandung Dalam 3 jam Tuntas Hub: 081226652077

Jual Obat Aborsi Bekasi | Obat Aborsi Tuntas | Obat Telat Bulan Manjur

Jual Obat Aborsi Palembang Dalam 3 jam Tuntas Hub: 081226652077

Jual Obat Aborsi Pekanbaru | Obat Telat Bulan | Obat Aborsi Tuntas

Jual Obat Aborsi Makassar Dalam 3 jam Tuntas Hub: 081226652077

JUAL OBAT ABORSI | OBAT PENGGUGUR KANDUNGAN AMAN

jual obat aborsi

jual obat aborsi jakarta

jual obat aborsi surabaya

javis shob01 dijo...

Obat Aborsi bandung
Obat Aborsi bekasi
Obat Aborsi bekasi
Obat Aborsi malang
Obat Aborsi palembang
Obat Aborsi makassar
Obat Aborsi sidoarjo
jual Obat Aborsi
Obat Aborsi samarinda
Obat Aborsi aman

Dr. Lina dijo...



Jual obat aborsi cytotec
Jual obat aborsi makassar

Jual obat aborsi bandung
Jual obat aborsi batam
Jual obat aborsi malang
Jual obat aborsi palembang

Jual obat aborsi semarang

Jual obat aborsi jakarta

Jual obat aborsi bekasi

Jual obat aborsi surabaya

Jual obat aborsi di Semarang, Jogja, yogyakarta,Malang, Surabaya, Jakarta, Bandung, Bekasi, Batam, Palembang dan Makassar.

Penirum Shop dijo...

Jual Viagra Asli Di Jakarta Barat
Jual Viagra Asli Di Jakarta Pusat
Jual Obat Penirum Asli Di Jakarta Barat
Jual Obat Penirum Asli Di Jakarta Selatan
Jual Obat Penirum Asli Di Jakarta Utara
Jual Obat Penirum Asli Di Jakarta Timur
Jual Obat Penirum Asli Di Jakarta Pusat

luckylancar dijo...

Alat Bantu Sex Di Bandung
Jual Alat Bantu Sextoys Di Bandung
Alat Sextoys Di Bandung
Alat Sextoys Pria Di Bandung
Alat Sextoys Wanita Di Bandung
Alat Sextoys Lengkap Di Bandung
Jual Cialis 80Mg Di Bandung
Jual Hammer Of Thor Asli Di Bandung
Jual Klg Asli Di Bandung

Dr. Ratna Klinik dijo...

Jual obat aborsi pontianak

Jual obat aborsi cimahi

Jual obat aborsi samarinda

Jual obat aborsi deli serdang

Jual obat aborsi cytotec

Jual obat aborsi jakarta

Jual obat aborsi banda aceh

Jual obat aborsi ternate

Jual obat aborsi batam


Dr. Ratna Klinik dijo...

Jual obat aborsi tebing tinggi

Jual obat aborsi kendal

Jual obat aborsi medan

Jual obat aborsi sragen

Jual obat aborsi tegal

Jual obat aborsi tangerang

Jual obat aborsi palembang

Jual obat aborsi karawang

Jual obat aborsi sumatra barat

Jual obat aborsi cikampek

Cytotec Online dijo...

점을 보완하여 Cytotec 양자대결이나 라이벌 대결 등으로 사전에 10점을 심사위원 Cytotec Misoprostol 재량으로 줄 수 있는 권한까지 부여하였다. 그러함에도 불구하고 Obat Telat Datang Bulan 실력면에서 상대적으로 월등한 송희진의 3강에서 결승에 오르지 못하자 Gastrul 심사위원들은 멘붕에 빠졌다

pedet jos dijo...

obat aborsi ampuh
obat aborsi aman
obat aborsi malang
obat aborsi palembang
obat aborsi makassar
obat aborsi solo
obat aborsi bekasi
obat aborsi bandung

obat aborsi tuntas
obat aborsi bali
obat aborsi solo

Obat Aborsi Cinajur dijo...

Obat Aborsi Aman ,
Cara Menggugurkan Kandungan Paling Cepat ,

Sang Raja dijo...

Obat Aborsi Malang ,

Obat Aborsi Surabaya ,

Obat Aborsi Kuta Bali ,

Obat Aborsi Blitar ,

Obat Aborsi Gianyar ,

Obat Aborsi Di Denpasar ,

Obat Aborsi Di Bali ,

Obat Aborsi Kediri ,

Obat Aborsi Gresik ,