use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.
the class OrderedMessageSendingIntegrationTests method setup.
@BeforeEach
public void setup() {
this.blockingSession = new BlockingWebSocketSession();
this.blockingSession.setId("1");
this.blockingSession.setOpen(true);
this.executor = new ThreadPoolTaskExecutor();
this.executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
this.executor.setAllowCoreThreadTimeOut(true);
this.executor.afterPropertiesSet();
this.subscribableChannel = new ExecutorSubscribableChannel(this.executor);
OrderedMessageChannelDecorator.configureInterceptor(this.subscribableChannel, true);
this.orderedMessageChannel = new OrderedMessageChannelDecorator(this.subscribableChannel, logger);
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project pinpoint by naver.
the class NodeHistogramAppenderTest method appendNodeHistogram.
@Test
public void appendNodeHistogram() throws InterruptedException {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(16);
executor.setMaxPoolSize(16);
executor.setQueueCapacity(1024);
int maxCount = 100;
CompletableFuture[] array = new CompletableFuture[maxCount];
AtomicBoolean timeout = new AtomicBoolean(false);
for (int i = 0; i < maxCount; i++) {
array[i] = makeCompletableFuture(i, timeout);
}
CompletableFuture completableFuture = CompletableFuture.allOf(array);
try {
completableFuture.get(100, TimeUnit.MILLISECONDS);
} catch (Exception e) {
timeout.set(Boolean.TRUE);
}
TimeUnit.SECONDS.sleep(3);
System.out.println("END");
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project perun by CESNET.
the class UserSynchronizer method synchronizeUsers.
public void synchronizeUsers() {
PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
ThreadPoolTaskExecutor syncExecutor = new ThreadPoolTaskExecutor();
int poolIndex;
boolean shouldWriteExceptionLog = true;
for (poolIndex = 0; poolIndex < perunUser.length; poolIndex++) {
perunUser[poolIndex] = context.getBean("perunUser", PerunUser.class);
}
try {
log.debug("Getting list of users");
List<User> users = perun.getUsersManagerBl().getUsers(ldapcManager.getPerunSession());
Set<Name> presentUsers = new HashSet<Name>(users.size());
syncExecutor.setCorePoolSize(5);
syncExecutor.setMaxPoolSize(8);
// syncExecutor.setQueueCapacity(30);
syncExecutor.initialize();
poolIndex = 0;
taskCount = new AtomicInteger(0);
for (User user : users) {
presentUsers.add(perunUser[0].getEntryDN(String.valueOf(user.getId())));
log.debug("Getting list of attributes for user {}", user.getId());
List<Attribute> attrs = new ArrayList<Attribute>();
List<String> attrNames = fillPerunAttributeNames(perunUser[poolIndex].getPerunAttributeNames());
try {
// log.debug("Getting attribute {} for user {}", attrName, user.getId());
attrs.addAll(perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), user, attrNames));
/* very chatty
if(attr == null) {
log.debug("Got null for attribute {}", attrName);
} else if (attr.getValue() == null) {
log.debug("Got attribute {} with null value", attrName);
} else {
log.debug("Got attribute {} with value {}", attrName, attr.getValue().toString());
}
*/
} catch (PerunRuntimeException e) {
log.warn("Couldn't get attributes {} for user {}: {}", attrNames, user.getId(), e.getMessage());
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
log.debug("Got attributes {}", attrNames.toString());
try {
// log.debug("Synchronizing user {} with {} attrs", user, attrs.size());
// perunUser.synchronizeEntry(user, attrs);
log.debug("Getting list of member groups for user {}", user.getId());
Set<Integer> voIds = new HashSet<>();
List<Member> members = perun.getMembersManagerBl().getMembersByUser(ldapcManager.getPerunSession(), user);
List<Group> groups = new ArrayList<Group>();
for (Member member : members) {
if (member.getStatus().equals(Status.VALID)) {
voIds.add(member.getVoId());
groups.addAll(perun.getGroupsManagerBl().getAllGroupsWhereMemberIsActive(ldapcManager.getPerunSession(), member));
}
}
// log.debug("Synchronizing user {} with {} VOs and {} groups", user.getId(), voIds.size(), groups.size());
// perunUser.synchronizeMembership(user, voIds, groups);
log.debug("Getting list of extSources for user {}", user.getId());
List<UserExtSource> userExtSources = perun.getUsersManagerBl().getUserExtSources(ldapcManager.getPerunSession(), user);
List<Group> admin_groups = perun.getUsersManagerBl().getGroupsWhereUserIsAdmin(ldapcManager.getPerunSession(), user);
List<Vo> admin_vos = perun.getUsersManagerBl().getVosWhereUserIsAdmin(ldapcManager.getPerunSession(), user);
List<Facility> admin_facilities = perun.getFacilitiesManagerBl().getFacilitiesWhereUserIsAdmin(ldapcManager.getPerunSession(), user);
// log.debug("Synchronizing user {} with {} extSources", user.getId(), userExtSources.size());
// perunUser.synchronizePrincipals(user, userExtSources);
syncExecutor.execute(new SyncUsersWorker(poolIndex, user, attrs, voIds, groups, userExtSources, admin_groups, admin_vos, admin_facilities));
taskCount.incrementAndGet();
} catch (PerunRuntimeException e) {
log.error("Error synchronizing user", e);
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
poolIndex = (poolIndex + 1) % perunUser.length;
}
try {
removeOldEntries(perunUser[0], presentUsers, log);
} catch (InternalErrorException e) {
log.error("Error removing old user entries", e);
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
} catch (PerunRuntimeException e) {
if (shouldWriteExceptionLog) {
log.error("Error synchronizing users", e);
}
throw new InternalErrorException(e);
} finally {
// wait for all the tasks to get executed
while (!syncExecutor.getThreadPoolExecutor().getQueue().isEmpty()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
// wait for all the tasks to complete (for at most 10 seconds)
for (int i = 0; i < 10 && taskCount.get() > 0; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
syncExecutor.shutdown();
for (poolIndex = 0; poolIndex < perunUser.length; poolIndex++) {
perunUser[poolIndex] = null;
}
}
if (wasThreadException) {
throw new InternalErrorException("Error synchronizing user in executed thread");
}
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-boot by spring-projects.
the class TaskExecutorMetricsAutoConfigurationTests method taskExecutorsWithCustomNamesAreInstrumented.
@Test
void taskExecutorsWithCustomNamesAreInstrumented() {
this.contextRunner.withBean("firstTaskExecutor", Executor.class, ThreadPoolTaskExecutor::new).withBean("customName", ThreadPoolTaskExecutor.class, ThreadPoolTaskExecutor::new).run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
Collection<FunctionCounter> meters = registry.get("executor.completed").functionCounters();
assertThat(meters).map((meter) -> meter.getId().getTag("name")).containsExactlyInAnyOrder("firstTaskExecutor", "customName");
});
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-boot by spring-projects.
the class TaskExecutionAutoConfigurationTests method taskExecutorBuilderShouldApplyCustomizer.
@Test
void taskExecutorBuilderShouldApplyCustomizer() {
this.contextRunner.withUserConfiguration(TaskExecutorCustomizerConfig.class).run((context) -> {
TaskExecutorCustomizer customizer = context.getBean(TaskExecutorCustomizer.class);
ThreadPoolTaskExecutor executor = context.getBean(TaskExecutorBuilder.class).build();
then(customizer).should().customize(executor);
});
}
Aggregations