use of org.nutz.lang.Stopwatch in project nutzboot by nutzam.
the class NbApp method execute.
public boolean execute() {
Stopwatch sw = Stopwatch.begin();
try {
// 各种预备操作
listener.whenPrepare(this, EventType.before);
this.prepare();
listener.whenPrepare(this, EventType.after);
// 依次启动
listener.whenInitAppContext(this, EventType.before);
ctx.init();
listener.whenInitAppContext(this, EventType.after);
listener.whenStartServers(this, EventType.before);
ctx.startServers();
listener.whenStartServers(this, EventType.after);
if (ctx.getMainClass().getAnnotation(IocBean.class) != null)
ctx.getIoc().get(ctx.getMainClass());
listener.afterAppStated(this);
sw.stop();
log.infof("%s started : %sms", ctx.getConf().get("nutz.application.name", "NB"), sw.du());
started = true;
return true;
} catch (Throwable e) {
log.error("something happen!!", e);
return false;
}
}
use of org.nutz.lang.Stopwatch in project nutzboot by nutzam.
the class NbMvcLoading method depose.
public void depose(NutConfig config) {
if (log.isInfoEnabled())
log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName());
Stopwatch sw = Stopwatch.begin();
// Firstly, upload the user customized desctroy
try {
Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName());
if (null != setup)
setup.destroy(config);
} catch (Exception e) {
throw new LoadingException(e);
}
// Done, print info
sw.stop();
if (log.isInfoEnabled())
log.infof("Nutz.Mvc[%s] is down in %sms", config.getAppName(), sw.getDuration());
}
use of org.nutz.lang.Stopwatch in project nutz by nutzam.
the class NutLoading method depose.
public void depose(NutConfig config) {
if (log.isInfoEnabled())
log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName());
Stopwatch sw = Stopwatch.begin();
// Firstly, upload the user customized desctroy
try {
Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName());
if (null != setup)
setup.destroy(config);
} catch (Exception e) {
throw new LoadingException(e);
} finally {
SessionProvider sp = config.getSessionProvider();
if (sp != null)
sp.notifyStop();
// If the application has Ioc, depose it
Ioc ioc = config.getIoc();
if (null != ioc)
ioc.depose();
}
// Done, print info
sw.stop();
if (log.isInfoEnabled())
log.infof("Nutz.Mvc[%s] is down in %sms", config.getAppName(), sw.getDuration());
}
use of org.nutz.lang.Stopwatch in project nutz by nutzam.
the class UploadingSpeedTest method main.
public static void main(String[] args) {
if (0 == args.length) {
System.err.println("Lack files directory!");
System.exit(0);
}
File dir = Files.findFile(args[0]);
if (null == dir) {
System.err.println("Fail to found directory: " + args[0]);
System.exit(0);
}
final Uploading up = UploadUnit.TYPE.born();
final UploadingContext uc = UploadingContext.create("~/nutz/unit/uploadtmp");
File[] files = dir.listFiles();
final MockHttpServletRequest req = request().setInputStream(insmulti("UTF-8", files));
req.setSession(session(context()));
req.init();
Object monLock = new Object();
int monInterval = 2000;
UploadMonitor mon = new UploadMonitor(monLock, req.getSession(), out, monInterval);
Thread monThread = new Thread(mon, "UploadingMonitor");
monThread.start();
out.println("Begin...");
Stopwatch sw = null;
try {
sw = Stopwatch.run(new Atom() {
public void run() {
try {
up.parse(req, uc);
} catch (UploadException e) {
throw Lang.wrapThrow(e);
}
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
mon.stop();
out.println("\n...Done!");
if (null != sw)
out.println(sw);
}
}
use of org.nutz.lang.Stopwatch in project nutz by nutzam.
the class FastClassFactoryTest method testInvokeObjectMethodObjectArray.
@Test
public void testInvokeObjectMethodObjectArray() throws Throwable {
DefaultClassDefiner.debugDir = Disks.normalize("~/nutz_fastclass/");
FastMethod fc = FastMethodFactory.make(Pet.class.getConstructor());
fc = FastMethodFactory.make(Pet.class.getConstructor());
// net.sf.cglib.reflect.FastClass fc2 = net.sf.cglib.reflect.FastClass.create(Pet.class);
Mirror<Pet> mirror = Mirror.me(Pet.class);
Borning<Pet> mb = mirror.getBorning();
for (int i = 0; i < 10000; i++) {
if (null == fc.invoke(null))
throw new RuntimeException();
}
for (int i = 0; i < 10000; i++) {
new Pet();
}
for (int i = 0; i < 10000; i++) {
mb.born();
}
// for (int i = 0; i < 10000; i++) {
// fc2.newInstance();
// }
System.gc();
Lang.quiteSleep(1000);
System.gc();
Pet pet = null;
Stopwatch sw = Stopwatch.begin();
for (int i = 0; i < 1000000; i++) {
pet = new Pet();
}
sw.stop();
System.out.println("Native New :" + sw);
System.gc();
Lang.quiteSleep(1000);
System.gc();
sw = Stopwatch.begin();
for (int i = 0; i < 1000000; i++) {
pet = (Pet) fc.invoke(null);
}
sw.stop();
System.out.println("FastClass born:" + sw);
System.gc();
Lang.quiteSleep(1000);
System.gc();
sw = Stopwatch.begin();
for (int i = 0; i < 1000000; i++) {
pet = mb.born();
}
sw.stop();
System.out.println("mirror born :" + sw);
System.gc();
Lang.quiteSleep(1000);
System.gc();
sw = Stopwatch.begin();
for (int i = 0; i < 1000000; i++) {
new Object();
}
sw.stop();
System.out.println("NULL :" + sw);
System.gc();
Lang.quiteSleep(1000);
System.gc();
// System.gc();
if (pet != null)
System.out.println(FastClassFactory.get(Pet.class.getMethod("hashCode")).invoke(pet));
}
Aggregations