multithreading - Verifying thread safety with JUnit -


i test if code thread safe calling multiple threads @ same time different parameters. below example of how code want test looks like

public void writestringtofile(string filename, string tobewritten) {     //some implementation junit should not care. } 

in above code want verify if code thread safe if invoked different file names multiple threads @ same time. how should design junit easy understand , maintain?

if changed code public void writestringtooutputstream(outputstream out, string tobewritten) (or made actual implementation, , original method thin wrapper), pass filteroutputstream looks out concurrent writes, possibly blocking while other potential concurrent writes can try execute.

but checks writes aren't concurrent, not class isn't thread-safe. if detect concurrent writes, read data , make sure it's valid.


Comments

Popular posts from this blog

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -