Created
April 20, 2012 13:30
-
-
Save reikje/2428573 to your computer and use it in GitHub Desktop.
Don't let these ThreadLocals escape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A aspect which has the same functionality as the ServletRequestCleanupFilter. The {@link NonServletRequestCleanupAspect} | |
| * is useful when code is executed which is not wrapped by the servlet filter, i.e. the handling of events in the | |
| * thread pools. | |
| * | |
| * @author reik, 4/19/12 | |
| */ | |
| @Aspect | |
| public class NonServletRequestCleanupAspect { | |
| @Pointcut("execution(void package.listeners.PartnerNotificationListener+.onApplicationEvent(..))") | |
| public void onPartnerNotification() { } | |
| @Pointcut("execution(void package.listeners.SaveUserEventListener+.onApplicationEvent(..))") | |
| public void onSaveUserEvent() { } | |
| @Pointcut("onPartnerNotification() || onSaveUserEvent()") | |
| public void onApplicationEventWithDatabaseAccess() { } | |
| @Around("package.NonServletRequestCleanupAspect.onApplicationEventWithDatabaseAccess()") | |
| public Object addCleaner(final ProceedingJoinPoint pjp) throws Throwable { | |
| try { | |
| CleanupService.setCleaner(this); | |
| return pjp.proceed(); | |
| } finally { | |
| CleanupService.cleanup(this); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <filter-mapping> | |
| <filter-name>servletRequestCleanupFilter</filter-name> | |
| <url-pattern>/rpc/*</url-pattern> | |
| <url-pattern>/fb/*</url-pattern> | |
| </filter-mapping> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment