我正在使用Spring的ApplicationEventMulticaster。
如何在收听事件时配置未捕获的错误处理?
public ApplicationEventMulticaster asyncApplicationEventMulticaster() {
SimpleApplicationEventMulticaster eventMulticaster = new
SimpleApplicationEventMulticaster();
eventMulticaster.setTaskExecutor(getAsyncExecutor());
return eventMulticaster;
}
答案 0 :(得分:0)
包裹遗嘱执行人:
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <malloc.h>
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
struct node {
int n_number;
struct node *n_next;
} *head = NULL;
static void cleanup_handler(void *arg)
{
printf("Cleanup handler of second thread\n");
free(arg);
pthread_mutex_unlock(&mtx);
}
static void *thread_func(void *arg) // customer
{
struct node *p = NULL;
pthread_cleanup_push(cleanup_handler, p);
while (1)
{
if(
pthread_mutex_lock(&mtx);
while (head == NULL || (flag=0)){ pthread_cond_wait(&cond,&mtx);}
p = head;
head = head->n_next;
printf("Got %d from front of queue\n", p->n_number);
free(p);
pthread_mutex_unlock(&mtx);
else
}
pthread_exit(NULL);
pthread_cleanup_pop(0); // must be put in last line
}
int main(void)
{
pthread_t tid;
int i;
struct node *p;
pthread_create(&tid, NULL, thread_func, NULL);
for (i = 0; i < 10; i++) // producer
{
p = (struct node*)malloc(sizeof(struct node));
p->n_number = i;
pthread_mutex_lock(&mtx);// because head is share,visit share data must
be add lock/mutex
p->n_next = head;
head = p;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mtx);
sleep(1);
}
printf("thread 1 wanna end the line.So cancel thread 2.\n");
pthread_cancel(tid);
pthread_join(tid, NULL);
printf("All done------exiting\n");
return 0;
}
$gcc -o producer_customer_linkedlist producer_customer_linkedlist.c -lpthread
producer_customer_linkedlist.c: In function ‘thread_func’:
producer_customer_linkedlist.c:28:26: error: expected ‘)’ before ‘;’ token
pthread_mutex_lock(&mtx);
^
producer_customer_linkedlist.c:36:2: error: expected expression before ‘}’ token
}
^