use of org.springframework.util.StopWatch in project tutorials by eugenp.
the class TransactionalService method getQuickHowManyVisits.
public Integer getQuickHowManyVisits() {
try {
TransactionManager tm = transactionalCache.getAdvancedCache().getTransactionManager();
tm.begin();
Integer howManyVisits = transactionalCache.get(KEY);
howManyVisits++;
System.out.println("Ill try to set HowManyVisits to " + howManyVisits);
StopWatch watch = new StopWatch();
watch.start();
transactionalCache.put(KEY, howManyVisits);
watch.stop();
System.out.println("I was able to set HowManyVisits to " + howManyVisits + " after waiting " + watch.getTotalTimeSeconds() + " seconds");
tm.commit();
return howManyVisits;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
use of org.springframework.util.StopWatch in project TeachingInSimulation by ScOrPiOzzy.
the class FileDownload method testConcurrent.
@Test
public void testConcurrent() throws Exception {
FTPUtils util = getUtil("anonymous", "");
StopWatch w = new StopWatch();
w.start("开始下载");
InputStream stream = util.downloadFile("/assets/Model/", "11.j3o");
FileOutputStream out;
try {
File file;
out = new FileOutputStream(file = new File("model-file-" + 0));
Util.copyStream(stream, out);
out.close();
// 服务器中11.j3o文件大小是3,506,624
Assert.assertEquals(3506624, file.length());
w.stop();
System.out.println(w.getTotalTimeMillis());
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.springframework.util.StopWatch in project WTFDYUM by jchampemont.
the class CronServiceImpl method checkCredentials.
@Override
@Scheduled(fixedDelayString = "${wtfdyum.credentials-check-delay}", initialDelay = 120000L)
public void checkCredentials() {
log.debug("Checking credentials...");
final StopWatch watch = new StopWatch();
watch.start();
final Set<Long> members = principalService.getMembers();
for (final Long userId : members) {
final Principal principal = principalService.get(userId);
if (!twitterService.verifyCredentials(principal)) {
userService.applyLimit(userId, UserLimitType.CREDENTIALS_INVALID);
userService.addEvent(userId, new Event(EventType.INVALID_TWITTER_CREDENTIALS, ""));
} else {
userService.resetLimit(userId, UserLimitType.CREDENTIALS_INVALID);
}
}
watch.stop();
log.debug("Finished checking credentials in {} ms", watch.getTotalTimeMillis());
}
use of org.springframework.util.StopWatch in project WTFDYUM by jchampemont.
the class CronServiceImpl method cron.
@Override
@Scheduled(fixedDelayString = "${wtfdyum.unfollow-check-delay}", initialDelay = 120000L)
public void cron() {
log.debug("Starting cron method...");
final StopWatch watch = new StopWatch();
watch.start();
final Set<Long> members = principalService.getMembers();
for (final Long userId : members) {
try {
final Set<Feature> enabledFeatures = userService.getEnabledFeatures(userId);
final Set<Event> events = new HashSet<>();
for (final Feature enabledFeature : enabledFeatures) {
final Set<Event> es = featureService.cron(userId, enabledFeature);
events.addAll(es);
}
for (final Event e : events) {
userService.addEvent(userId, e);
}
for (final Feature enabledFeature : enabledFeatures) {
featureService.completeCron(userId, enabledFeature);
}
} catch (final WTFDYUMException e) {
if (WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED.equals(e.getType())) {
userService.addEvent(userId, new Event(EventType.RATE_LIMIT_EXCEEDED, null));
log.warn("GET_FOLLOWERS_RATE_LIMIT_EXCEEDED for user id {}", userId);
} else {
userService.addEvent(userId, new Event(EventType.TWITTER_ERROR, null));
log.error("Twitter error for userId " + userId, e.getCause());
}
} catch (final Throwable t) {
userService.addEvent(userId, new Event(EventType.UNKNOWN_ERROR, null));
log.error("Unknown error for user id " + userId, t);
}
}
watch.stop();
log.debug("Finished cron in {} ms", watch.getTotalTimeMillis());
}
use of org.springframework.util.StopWatch in project spring-security by spring-projects.
the class ProtectPointcutPerformanceTests method usingPrototypeDoesNotParsePointcutOnEachCall.
// Method for use with profiler
@Test
public void usingPrototypeDoesNotParsePointcutOnEachCall() {
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000; i++) {
try {
SessionRegistry reg = (SessionRegistry) this.ctx.getBean("sessionRegistryPrototype");
reg.getAllPrincipals();
fail("Expected AuthenticationCredentialsNotFoundException");
} catch (AuthenticationCredentialsNotFoundException expected) {
}
}
sw.stop();
// assertThat(sw.getTotalTimeMillis() < 1000).isTrue();
}
Aggregations