开发者

How to delete certain characters from multiple text files, in a thread safe way?

What is the best way, to develop a multi threaded program, to delete certain characters from multiple text files that are passed in as parameters?

Thus, when someone passes a开发者_如何学JAVAs a.out axvc f1 f2 f3 f4 , the goal is to delete all occurences of the characters a,x,v,c from the file f1, f2, f3 and f4.


Are you not able to just make use of normal utilities like sed to help you do this?

Even if you aren't, are you sure that the CPU use is a significant enough portion of the processing time that it wouldn't be dwarfed by the file I/O? Most likely doing it in multiple threads won't save you much time at all vs doing it serially in one thread.

Otherwise probably the easiest mechanism would be to have the main thread doing the I/O and dispatching work to a pool of worker threads that do the character removal. It gets trickier if I/O speed actually improves when being done from multiple threads.


Is there a particular reason you want to use multiple threads to do this? If the files are on the same device that won't help at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜