Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit ad5b4eb

Browse files
committed
Merge pull request #29 from kenkyoung/master
Example Project for SPR-9575
2 parents 4810d5b + e527196 commit ad5b4eb

21 files changed

+959
-0
lines changed

SPR-9575/pom.xml

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-9575</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Spring MVC Issue Reproduction Project</name>
8+
<packaging>war</packaging>
9+
10+
<properties>
11+
<java-version>1.6</java-version>
12+
<org.springframework-version>3.1.2.RELEASE</org.springframework-version>
13+
<org.slf4j-version>1.6.1</org.slf4j-version>
14+
</properties>
15+
16+
<dependencies>
17+
<!-- Spring Framework -->
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-context</artifactId>
21+
<version>${org.springframework-version}</version>
22+
<exclusions>
23+
<!-- Exclude Commons Logging in favor of SLF4j -->
24+
<exclusion>
25+
<groupId>commons-logging</groupId>
26+
<artifactId>commons-logging</artifactId>
27+
</exclusion>
28+
</exclusions>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-webmvc</artifactId>
33+
<version>${org.springframework-version}</version>
34+
</dependency>
35+
36+
<!-- Logging -->
37+
<dependency>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-api</artifactId>
40+
<version>${org.slf4j-version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.slf4j</groupId>
44+
<artifactId>jcl-over-slf4j</artifactId>
45+
<version>${org.slf4j-version}</version>
46+
<scope>runtime</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.slf4j</groupId>
50+
<artifactId>slf4j-log4j12</artifactId>
51+
<version>${org.slf4j-version}</version>
52+
<scope>runtime</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>log4j</groupId>
56+
<artifactId>log4j</artifactId>
57+
<version>1.2.16</version>
58+
<scope>runtime</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>com.google.guava</groupId>
63+
<artifactId>guava</artifactId>
64+
<version>12.0</version>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>ro.isdc.wro4j</groupId>
69+
<artifactId>wro4j-core</artifactId>
70+
<version>1.4.6</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>ro.isdc.wro4j</groupId>
74+
<artifactId>wro4j-extensions</artifactId>
75+
<version>1.4.6</version>
76+
</dependency>
77+
78+
<!-- Servlet API -->
79+
<dependency>
80+
<groupId>javax.servlet</groupId>
81+
<artifactId>servlet-api</artifactId>
82+
<version>2.5</version>
83+
<scope>provided</scope>
84+
</dependency>
85+
86+
<!-- JSP API and JSTL -->
87+
<dependency>
88+
<groupId>javax.servlet.jsp</groupId>
89+
<artifactId>jsp-api</artifactId>
90+
<version>2.1</version>
91+
<scope>provided</scope>
92+
</dependency>
93+
<dependency>
94+
<groupId>javax.servlet</groupId>
95+
<artifactId>jstl</artifactId>
96+
<version>1.2</version>
97+
</dependency>
98+
99+
100+
101+
102+
<!-- Apache Tiles
103+
<dependency>
104+
<groupId>org.apache.tiles</groupId>
105+
<artifactId>tiles-jsp</artifactId>
106+
<version>2.1.3</version>
107+
<exclusions>
108+
<exclusion>
109+
<groupId>commons-logging</groupId>
110+
<artifactId>commons-logging-api</artifactId>
111+
</exclusion>
112+
</exclusions>
113+
</dependency>
114+
-->
115+
116+
<!-- JSR 303 with Hibernate Validator
117+
<dependency>
118+
<groupId>javax.validation</groupId>
119+
<artifactId>validation-api</artifactId>
120+
<version>1.0.0.GA</version>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.hibernate</groupId>
124+
<artifactId>hibernate-validator</artifactId>
125+
<version>4.1.0.Final</version>
126+
</dependency>
127+
-->
128+
129+
<!-- Joda Time Library
130+
<dependency>
131+
<groupId>joda-time</groupId>
132+
<artifactId>joda-time</artifactId>
133+
<version>1.6.2</version>
134+
</dependency>
135+
<dependency>
136+
<groupId>joda-time</groupId>
137+
<artifactId>joda-time-jsptags</artifactId>
138+
<version>1.0.2</version>
139+
<scope>runtime</scope>
140+
</dependency>
141+
-->
142+
143+
<!-- Apache Commons File Upload
144+
<dependency>
145+
<groupId>commons-fileupload</groupId>
146+
<artifactId>commons-fileupload</artifactId>
147+
<version>1.2.2</version>
148+
</dependency>
149+
<dependency>
150+
<groupId>commons-io</groupId>
151+
<artifactId>commons-io</artifactId>
152+
<version>2.0.1</version>
153+
</dependency>
154+
-->
155+
156+
<!-- Jackson JSON Processor-->
157+
<dependency>
158+
<groupId>org.codehaus.jackson</groupId>
159+
<artifactId>jackson-mapper-asl</artifactId>
160+
<version>1.8.1</version>
161+
</dependency>
162+
163+
164+
<!-- Rome Atom+RSS
165+
<dependency>
166+
<groupId>rome</groupId>
167+
<artifactId>rome</artifactId>
168+
<version>1.0</version>
169+
</dependency>
170+
-->
171+
172+
<!-- Test -->
173+
<dependency>
174+
<groupId>junit</groupId>
175+
<artifactId>junit</artifactId>
176+
<version>4.8</version>
177+
<scope>test</scope>
178+
</dependency>
179+
</dependencies>
180+
181+
<repositories>
182+
<repository>
183+
<id>spring-maven-snapshot</id>
184+
<name>Springframework Maven Snapshot Repository</name>
185+
<url>http://repo.springsource.org/snapshot</url>
186+
<snapshots>
187+
<enabled>true</enabled>
188+
</snapshots>
189+
</repository>
190+
</repositories>
191+
192+
<build>
193+
<plugins>
194+
<plugin>
195+
<artifactId>maven-compiler-plugin</artifactId>
196+
<configuration>
197+
<source>${java-version}</source>
198+
<target>${java-version}</target>
199+
</configuration>
200+
</plugin>
201+
<plugin>
202+
<groupId>org.apache.maven.plugins</groupId>
203+
<artifactId>maven-dependency-plugin</artifactId>
204+
<executions>
205+
<execution>
206+
<id>install</id>
207+
<phase>install</phase>
208+
<goals>
209+
<goal>sources</goal>
210+
</goals>
211+
</execution>
212+
</executions>
213+
</plugin>
214+
<plugin>
215+
<groupId>org.apache.maven.plugins</groupId>
216+
<artifactId>maven-eclipse-plugin</artifactId>
217+
<version>2.8</version>
218+
<configuration>
219+
<downloadSources>true</downloadSources>
220+
<downloadJavadocs>false</downloadJavadocs>
221+
<wtpversion>2.0</wtpversion>
222+
</configuration>
223+
</plugin>
224+
<plugin>
225+
<artifactId>maven-surefire-plugin</artifactId>
226+
<configuration>
227+
<includes>
228+
<include>**/*Tests.java</include>
229+
</includes>
230+
<excludes>
231+
<exclude>**/*Abstract*.java</exclude>
232+
</excludes>
233+
</configuration>
234+
</plugin>
235+
</plugins>
236+
</build>
237+
238+
</project>
239+

SPR-9575/src/main/java/org/springframework/issues/.gitignore

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.springframework.issues;
2+
3+
import java.util.concurrent.Future;
4+
5+
import org.springframework.scheduling.annotation.Async;
6+
import org.springframework.scheduling.annotation.AsyncResult;
7+
import org.springframework.stereotype.Component;
8+
9+
10+
11+
@Component("asyncProcess")
12+
public class AsyncProcess implements AsyncProcessInterface {
13+
14+
/* (non-Javadoc)
15+
* @see com.solutionary.service.AsyncProcessInterface#findBalanceAsync(java.lang.String)
16+
*/
17+
//("portalAsyncExecutor")
18+
19+
@Async("portalPoolTaskExecutor")
20+
public Future<String> findBalanceAsync(final String account) {
21+
long startTime = System.currentTimeMillis();
22+
23+
String threadName = Thread.currentThread().getName();
24+
25+
26+
long t= System.currentTimeMillis();
27+
long end = t+10000;//15 seconds
28+
if (account.equals("portlet2")){
29+
end = t+45000;
30+
}
31+
while(System.currentTimeMillis() < end) {
32+
// do something
33+
// pause to avoid churning
34+
35+
}
36+
long endTime = System.currentTimeMillis();
37+
String balance = Long.valueOf(endTime).toString()+" : "+threadName;
38+
System.out.println(threadName+" completes Async processing : "
39+
+ (endTime - startTime) / 1000 + " seconds for " + account);
40+
return new AsyncResult<String>(balance);
41+
}
42+
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.springframework.issues;
2+
3+
import java.util.concurrent.Future;
4+
5+
public interface AsyncProcessInterface {
6+
7+
8+
public abstract Future<String> findBalanceAsync(final String account);
9+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.springframework.issues;
2+
3+
4+
import java.util.concurrent.ExecutionException;
5+
import java.util.concurrent.Future;
6+
import java.util.concurrent.TimeUnit;
7+
import java.util.concurrent.TimeoutException;
8+
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.beans.factory.annotation.Qualifier;
11+
import org.springframework.stereotype.Service;
12+
13+
14+
15+
16+
@Service("asyncService")
17+
public class AsyncService {
18+
//@Qualifier("asyncProcessCopy")
19+
@Autowired
20+
@Qualifier("asyncProcess")
21+
private AsyncProcessInterface asyncProcess;
22+
23+
24+
25+
@Autowired
26+
@Qualifier("portletCache")
27+
private PortletCacheInterface portletCache;
28+
29+
public ResultDto findBalanceAsync(String targetDiv) throws Exception {
30+
31+
Future<String> future;
32+
ResultDto dto = new ResultDto();
33+
future = portletCache.get(targetDiv);
34+
if (future==null) {
35+
future = asyncProcess.findBalanceAsync(targetDiv);
36+
portletCache.put(targetDiv, future);
37+
}
38+
String result = "";
39+
try {
40+
result = future.get(3, TimeUnit.SECONDS);
41+
dto.setContent(result);
42+
dto.setProcessCode(ResultCode.COMPLETE);
43+
portletCache.remove(targetDiv);
44+
} catch (InterruptedException e) {
45+
e.printStackTrace();
46+
dto.setProcessCode(ResultCode.ERROR);
47+
} catch (ExecutionException e) {
48+
e.printStackTrace();
49+
dto.setProcessCode(ResultCode.ERROR);
50+
} catch (TimeoutException e) {
51+
result = "Processing ...";
52+
dto.setContent(result);
53+
dto.setProcessCode(ResultCode.PROCESSING);
54+
55+
}
56+
long size = portletCache.getSize();
57+
System.out.println("Cache Size: "+size+"; Result: "+result);
58+
59+
return dto;
60+
}
61+
}

0 commit comments

Comments
 (0)