I have the following lines of code in my application:
return "Service is alive since: " + TimeUnit.MILLISECONDS.toMinutes(mxBean.getUptime()) + " minutes";
It uses the following package:
import java.util.concurrent.TimeUnit;
My application is a web application. Does it means that I have something wrong logically if I use something from concurrent package at a web application?
1
Using TimeUnit.MILLISECONDS.toMinutes(…) is fine as it doesn’t actually invoke any threading behaviour (which would be incorrect in a Java EE container). It’s part of core Java, so no overheads.
I can’t see any problem with this, and in fact using TimeUnit.MILLISECONDS.toMinutes(...)
was the solution to the SO question that I found when googling “java convert milliseconds to minutes”.
If you were in a constrained environment where you were worried about the size of your deployment, you might need to try cutting out any packages or jars that you don’t need, but since java.util.concurrent is part of core Java, removing it would take some work.