Originally Posted by
fishtoprecords
While a random access file can handle it, I don't like doing this. Do you really need a single instance of the file?
That is the core question, I do not really need it, while coding yesterday I came up with:
public TemporaryOrderForm()
{
this.SessionMap = new java.util.TreeMap<Integer,OrderFormRequestObject>();//
}
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
{
try
{
init();
return;
}
catch(javax.servlet.ServletException SERVLET_EXCEPTION)
{
throw SERVLET_EXCEPTION;
}
}
// Kitty Litter.
public void init() throws javax.servlet.ServletException
{
try
{
// Logfile.
java.io.File LogFileObject = new java.io.File(logfileName);
if(LogFileObject.exists())
{
logFile = new java.io.FileWriter(LogFileObject,true);
logWriter = new java.io.BufferedWriter(logFile);
}
else
{
logFile = new java.io.FileWriter(LogFileObject);
logWriter = new java.io.BufferedWriter(logFile);
}
// Actions file.
java.io.File ActionsFileObject = new java.io.File(actionsName);
if(ActionsFileObject.exists())
{
actionsFile = new java.io.FileWriter(ActionsFileObject,true);
actionsWriter = new java.io.BufferedWriter(actionsFile);
}
else
{
actionsFile = new java.io.FileWriter(ActionsFileObject);
actionsWriter = new java.io.BufferedWriter(actionsFile);
}
// Belvedere file: reserved for unanticipated use.
java.io.File BelvedereFileObject = new java.io.File(belvedereName);
if(BelvedereFileObject.exists())
{
belvedereFile = new java.io.FileWriter(BelvedereFileObject,true);
belvedereWriter = new java.io.BufferedWriter(belvedereFile);
}
else
{
belvedereFile = new java.io.FileWriter(BelvedereFileObject);
belvedereWriter = new java.io.BufferedWriter(belvedereFile);
}
return;
}
That still leaves several knotty sync() issues, doing the round-robin may need a few additional file(s) to allow retirement of buffer issues but it would not be at all difficult for me to go to an array of five or six file handles and let Actions File settle down before retrieving. This approach could be put on a Timer and let the timer run for an hour or a day or something before doing a synchronized pointer rotation. I do not have the nomenclature in my forebrain, it is a standard approch to such things as tip of day and is discussed in my Algorithms in Java by Sedgewick ~ a useful text in that it is just a little ahead of me but well within reach and dispenses with the sophmorics.
or can you use the more standard approach, which is to open the file for read, open a new file as a temp file (perhaps even in /tmp) which you write to. At the end of the process, you close the read file, rename the temp file to the old name, and close everything.
Given your experiences with such things, given a Tier-1 rack that has a one-second turnaround for file-upload and tab over to browser then hit refresh, would we be on safe ground to round-robin once a day or something - leaving one of three for 'active file' one for 'settle-flush' and one for 'retrieval'?
This makes it so only one output file is in existance.
Line continuation char in source here for posting clarity only, not in development prototyping sources.
//
public void doPost(javax.servlet.http.HttpServletRequest request,...
{
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
//
synchronized(this)
{
String headerName = null;
String headerValue = null;
java.util.Enumeration HeaderEnumeration = request.getHeaderNames();
if(HeaderEnumeration.hasMoreElements())
{
do
{
headerName = (String)HeaderEnumeration.nextElement();
headerValue = request.getHeader(headerName);
logWriter.write(headerValue,0,headerValue.length());
logWriter.write(UNIT_SEPARATOR.toString(),\
0,UNIT_SEPARATOR.toString().length());
}
while(HeaderEnumeration.hasMoreElements());
logWriter.write(RECORD_SEPARATOR.toString(),\
0,RECORD_SEPARATOR.toString().length());// end of record
logWriter.newLine();
logWriter.flush();
}
}
javax.servlet.http.HttpSession SESSION = request.getSession(true);
String ServerSessionValue = SESSION.getId();//
//.....
I would not allow multiple threads to write, rather I'd use a queue to have all the reader threads put write commands to a single thread that does the work.
Basically, two threads doing file-writes on one system file handle is just too dicey without dedicated hardware and real system engineering. Okay, listen to voice of experienced reason from years of field experience watching others in the position I am in here.
If the server could use something like NFS for the file store, its not reliable to have multiple machines writing to a single file.
Okay, clear answer is that this is just too much to ask. KISS rules here.
Norm, that 256 was something I dug up recently while doing research on ..... is that an array in the background of your avatar? If so, why is a sky tracker backdrop for a optical nav tool being ( humor folks, humor ) used as a prop for your movie-carrer photo?