I can't seem to find the answer to this question I'm having:

Is the method from the ACRA library ...

ACRA.getErrorReporter().putCustomData(Name, Content);

... thread safe?

I'd like to call it from two different threads and I'm not sure if i should or not.

I've searched through the documentation but I wasn't able to find anything related to this unfortunately, or maybe I'm just a bad Googleler :)

有帮助吗?

解决方案 2

So I think I've figure it out.

Looking through the code I've noticed that the putCustomData method is in fact a call to a HashMap's method, more precisely put.

Upon further search I've found that the method put is not synchronized.

So the answer is no, calling putCustomData from two different threads can create problems for you.

For a solution to the problem: see 323go's idea below. In my case, I already had a singleton class which I used, so I just placed a synchronized method in that class in which I called the putCustomData method.

Note: If I am wrong, someone please let me know, but this is what I was able to find out.

其他提示

If you're not sure, buy some insurance:

ErrorReporter er = ACRA.getErrorReporter();
synchronized( er ) {
    er.putCustomData( ..., .... );
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top