Should ResultSetMapper implementations be thread safe?

74 views Asked by At

I have been trying to fold multiple rows within the same ResultSetMapper, i have a Map<String, MappedObj> map which i simply use to fold multiple rows to the same object as,

public MappedObj map(final int index, final ResultSet r, final StatementContext ctx) {
   MappedObj mappedObj = map.get(r.getString("Id"));
   if (mappedObj!=null){
      mappedObj.addValue(r.getString("RowToFold"));
   } else {
      mappedObj = new MappedObj();
      // Mapping
      map.put(mappedObj.getId(), mappedObj);
   }
   return mappedObj;
}

My concern is that, if ResultSetMapper::map is called in parallel, this code will break. From jdbi Query, i see that it is not called in parallel, however i am not sure if it means it is safe to implement them non thread-safe. Is my approach safe to use?

This is actually a general question. What is the default thread safety assumption on an interface implementation if it is not documented?

0

There are 0 answers