Am really starting to enjoy the power and portability of using Java in my load testing efforts, especially when the environments in which you work are often limited in terms of tool sets you’re allowed to use. For example the current Solaris environment I work in doesn’t have a C compiler native to the OS, so I am automatically limited in the amount of Perl code I can write, as I am lacking more powerful modules (that need to be compiled). Enter Java; it already comes installed and for the types of mid range services I’m working on (MQ, JMS etc) has loads of great APIs you can incorporate into your own custom test harnesses.
All good test harnesses are going to need to be multi-threaded, but I’ve had no idea on how to safely share data between threads! This problem has been annoying me for sometime, partly due to my own ignorance and lack of understanding of Java (indeed OO principles perhaps). But in any case, I was stuck in old (bad) habits of sharing data between threads. Normally I just assign a global variable but in OO design, that’s considered poor design, so here is my attempt at getting spawned threads of a ‘worker’ class sharing data via a common ‘datastore’ class.
Read More