Ok. I came across one such complex code -
Requirement:
Given an output log from a process which contains temporal information. Based on this temporal information, data need to be split and kept it in temporal directory structure. So, essentially, you have the data which contains when each line is generated and the data needs to be split and kept in directory structure like year/month/day/hour/filename.1 for 15 mins filename.2 for 30 mins worth of data and so on.
here is complicated version:
Have three threads - one is main thread , second thread creates a file for every 15 mins in above structure and third closes files created by previous thread. And the main thread reads each line from input and call write method. the stream handler will be modified by second thread for every 15 mins to point to new file. and will move the previous handler to queue and that is taken by third thread and closes it!!!!
here is simpler version:
for each inputline
check out the date
if it is with in minute domain write to same file
else close the previous file if any opened and create a new one
write inputline to output
close finally if there is any opened stream handler
Friday, May 29, 2009
Writing complex code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment