You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Sean Qiu <se...@gmail.com> on 2008/09/11 15:05:10 UTC
[classlib][logging] FileHandler may throw exception when logging to the same file by multiple thread
When we are trying to publish the log information by a Filehandler
into a same rotating set of files,
it will introduce multi-thread defect.
As a result, it will throw such exception[1] while logging.
The root cause is that the destination file may be deleted by other
thread if they are not synchronized.
I have created a jira[3] and attached a workaround for this problem.
I am concerned that the test case of this kind will bring performance
issue for our unit test,
since it is time-consuming and uncertainty.
My question is do we have any testing mechanism for this situation?
[1] Error message
java.util.logging.ErrorManager: WRITE_FAILURE
Error message - Exception occurred when writing to the output stream.
Exception - java.io.IOException: Writer is closed.
[2] Testcase
package logging;
import java.io.File;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
public class FileHandlerTest {
static class LoggingThread implements Runnable {
private Logger logger;
public LoggingThread(Logger logger){
this.logger = logger;
}
public void run() {
while (true) {
logger.info("Test");
}
}
}
public static void main(String[] args) throws Exception {
Logger logger = Logger.getLogger("test");
String path = new File(".").getAbsolutePath();
FileHandler fh = new FileHandler(path, 3000000, 12, false);
logger.setUseParentHandlers(false);
logger.addHandler(fh);
Thread[] threads = new Thread[12];
for (Thread thread : threads) {
thread = new Thread(new LoggingThread(logger));
thread.start();
}
}
}
[3] https://issues.apache.org/jira/browse/HARMONY-5981
--
Best Regards
Sean, Xiao Xia Qiu
China Software Development Lab, IBM
Re: [classlib][logging] FileHandler may throw exception when logging
to the same file by multiple thread
Posted by Tim Ellison <t....@gmail.com>.
Sean Qiu wrote:
> Sounds sensible.
> So could I commit it now without the test?
I would have no problem with that. Its a synchronized keyword not a
load of new functionality, and if you plan to submit a scenario test
then all the better.
Regards,
Tim
> 2008/9/11 Tim Ellison <t....@gmail.com>:
>> Sean Qiu wrote:
>>> When we are trying to publish the log information by a Filehandler
>>> into a same rotating set of files,
>>> it will introduce multi-thread defect.
>>>
>>> As a result, it will throw such exception[1] while logging.
>>> The root cause is that the destination file may be deleted by other
>>> thread if they are not synchronized.
>>>
>>> I have created a jira[3] and attached a workaround for this problem.
>>>
>>> I am concerned that the test case of this kind will bring performance
>>> issue for our unit test,
>>> since it is time-consuming and uncertainty.
>>> My question is do we have any testing mechanism for this situation?
>> How about creating a scenario test for it in the Build/Test
>> Infrastructure -- that's where we have put the other long running tests?
>>
>> Regards,
>> Tim
>>
>
>
>
Re: [classlib][logging] FileHandler may throw exception when logging to the same file by multiple thread
Posted by Sean Qiu <se...@gmail.com>.
Sounds sensible.
So could I commit it now without the test?
2008/9/11 Tim Ellison <t....@gmail.com>:
> Sean Qiu wrote:
>> When we are trying to publish the log information by a Filehandler
>> into a same rotating set of files,
>> it will introduce multi-thread defect.
>>
>> As a result, it will throw such exception[1] while logging.
>> The root cause is that the destination file may be deleted by other
>> thread if they are not synchronized.
>>
>> I have created a jira[3] and attached a workaround for this problem.
>>
>> I am concerned that the test case of this kind will bring performance
>> issue for our unit test,
>> since it is time-consuming and uncertainty.
>> My question is do we have any testing mechanism for this situation?
>
> How about creating a scenario test for it in the Build/Test
> Infrastructure -- that's where we have put the other long running tests?
>
> Regards,
> Tim
>
--
Best Regards
Sean, Xiao Xia Qiu
China Software Development Lab, IBM
Re: [classlib][logging] FileHandler may throw exception when logging
to the same file by multiple thread
Posted by Tim Ellison <t....@gmail.com>.
Sean Qiu wrote:
> When we are trying to publish the log information by a Filehandler
> into a same rotating set of files,
> it will introduce multi-thread defect.
>
> As a result, it will throw such exception[1] while logging.
> The root cause is that the destination file may be deleted by other
> thread if they are not synchronized.
>
> I have created a jira[3] and attached a workaround for this problem.
>
> I am concerned that the test case of this kind will bring performance
> issue for our unit test,
> since it is time-consuming and uncertainty.
> My question is do we have any testing mechanism for this situation?
How about creating a scenario test for it in the Build/Test
Infrastructure -- that's where we have put the other long running tests?
Regards,
Tim