Created
January 17, 2013 18:12
-
-
Save alexkasko/4558143 to your computer and use it in GitHub Desktop.
This file contains 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
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