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

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -