java - how can I count the number of exception thrown by threads? -
i have code:
@test public void setusernamepropertyfrommultithreadsupdatescorrectly() throws exception { boolean oldval = usersconfig.s.no_db_mode; final list<string> lastname = new arraylist<string>(); usersconfig.s.no_db_mode = true; string user1 = testutils.generateusername(); final long createdid = testutils.createuserwithproperties(immutablemap.of("username", user1, "a", "a1", "isstaff", "true")); list<callable<void>> callables = new arraylist<callable<void>>(); (int = 0; < 20; i++) { callables.add(new callable<void>() { @override public void call() throws exception { string user2 = testutils.generateusername(); boolean issuccess = usersserveraccess.setproperties(createdid, immutablemap.of("isstaff", "dont_know", "username", user2), 1, "test set", sometimeout); asserttrue(issuccess); synchronized (lastname) { lastname.add(user2); } return null; } }); executorservice executorservice = executors.newfixedthreadpool(10); try { executorservice.invokeall(callables); executorservice.shutdown(); executorservice.awaittermination(1, timeunit.minutes); } catch (interruptedexception e) { e.printstacktrace(); throw new runtimeexception(e); } user returneduser = usersserveraccess.getuser(createdid, "get test", sometimeout); assertthat(returneduser.getproperty("username"), equalto(lastname.get(0))); assertthat(returneduser.getproperty("a"), equalto("a1")); assertthat(returneduser.getproperty("isstaff"), equalto("dont_know")); }
i want assert none of threads threw exception.
how can this?
i can save aside future
list. what?
when execute get()
on future might executionexception, use getcause()
return actual exception.
Comments
Post a Comment