Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexkasko/4558143 to your computer and use it in GitHub Desktop.
Save alexkasko/4558143 to your computer and use it in GitHub Desktop.
public class BeanPropertySqlParameterSourceNotThreadSafeTest {
@Test
public void test() throws InterruptedException {
BeanPropertySqlParameterSource sps = new BeanPropertySqlParameterSource(new ImmutableClass());
Thread[] threads = new Thread[1000];
CountDownLatch latch = new CountDownLatch(1000);
for (int i = 0; i < 1000; i++) {
Thread th = new TestThread(latch, sps);
threads[i] = th;
th.start();
latch.countDown();
}
for(Thread th : threads) {
th.join();
}
}
private static class TestThread extends Thread {
private final CountDownLatch latch;
private final BeanPropertySqlParameterSource sps;
private TestThread(CountDownLatch latch, BeanPropertySqlParameterSource sps) {
this.latch = latch;
this.sps = sps;
}
@Override
public void run() {
try {
latch.await();
sps.getValue("date");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private static class ImmutableClass {
private final Date date = new Date();
public Date getDate() {
return date;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment