The concurrent io problem when using RandomAccessFile
Hi:
In my application,I have to export the tomcat log(the log file like "localhost_access_log.2010-10-13") to database and the do some analisis.
My way:
start to export log at 00:05:00 every day,at this moment just read the log whose date before yesterday.
For example,at 2010-12-12 00:05:00,the log of 2010-12-11... 2010-12-01 ..2010-11-12...(just check the nearest 30 days).
All of these data are put into one table named "log".
If log of one day is exported successfully,insert one record to another table named 'logrecord'.
//main code fragment:
public void start() {
//start the push export work once the server startup.
run();
//start the schedule work
new ScheduledThreadPoolExecutor(5).scheduleAtFixedRate(this, getStartTime(), 24 * 3600,
TimeUnit.SECONDS);
//return the left time(from now to 00:05:00 of tomorrow)
private long getStartTime() {
Date d = new Date();
long t = (DateUtil.getNextDayAtMiddleTime(d).getTime() - d.getTime()) / 1000 + 300;
return t;
@Override
public void run() {
Date days[] = DateUtil.getSeveralDayRangeByTime(30); //just the nearest 30 days.
for (Date d : days) {
if (exist(d)) {
continue;
exportLogByDate(d);
It works for now expect we can not anlyzer data of today.
However we need it now.
As far as I thought,I want to create a new table which owns the same structure of the former table "log" used to hold the log of "today" only.
At 00:05:00 of every day,after the normal log exporting(export the nearest 30 days'log but today),export the log of today.
It sounds easy,read the content,parser,filter,insert,just like what I did.
But,the tomcat log file is saved by day.So in my normal log exporting,the log file(nearest 30 days) are not be used by tomcat,I can open/close it as I like.
However if I tried to read the log of today,since the log file maybe used by tomcat for inserting log.
I prefer to use the RandomAccessFile to read the log of today:
But I am coufused by the concurrent io problem:what is going on if I am reading a line while tomcat is writing the line?
Here is my test exmaple:
package com.test;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestMain {
private static File file;
private static long pos; //record the position of last time
private static Thread writterThread;
@BeforeClass
public static void init() {
file = new File("D:/random.txt");
// build the thread for simulating the tomcat write log
writterThread = new Thread(new Runnable() {
@Override
public void run() {
FileWriter fw;
try {
fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
int i = 0;
while (true) {
i++;
bw.append(i + " added to line...");
bw.append("\r\n");
bw.flush();
Thread.sleep(5000);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
@Test
public void testRandomRead() throws IOException, InterruptedException {
writterThread.start();
try {
RandomAccessFile raf = new RandomAccessFile(file, "r");
String line;
while ((line = raf.readLine()) != null) {
System.out.println(line);
pos = raf.getFilePointer();
raf.close();
// read the file by 30 seconds within 2 min,just for test)
for (long m = 0; m < 1000 * 60 * 2; m += 30000) {
raf = new RandomAccessFile(file, "r");
raf.seek(pos);
while ((line = raf.readLine()) != null) {
System.out.println(line);
pos = raf.getFilePointer();
raf.close();
Thread.sleep(30000);
} catch (FileNotFoundException e) {
e.printStackTrace();
The normal output is something like:
1 added to line...
2 added to line...
3 added to line...
4 added to line...
5 added to line...
However I always get the following output:
1
added to line...
2 added to line...
3 added to line...
4 added to line...
5
added to line...
That's to say,the RandomAccessFile is reading the line which has not been completed by tomcat.
So,I have two questions now:
1) How about my normal log exporting? Is there anything can be improved?
2) How to slove the concurrent io problem when export log of today?
Peter Lawrey wrote:
You can;
- check the length to see if it has grown since the last time it was written to. If it has shrunk, start from the start of the file.
- if longer, open the file from the last point read.
- read the text up to the last newline in the file. (might be no new lines)
- close the file and remember where you were up to. (the start of the last incomplete line.
- wait a bit and repeat.But how to decide if one line is completed?
Also,how about if the randomaccessfile can not stop?
For example,start the work at 02:00,it read the tomcat log file line by line and export them to db,and during this time,the tomcat keep writing log to the same file(user request the server all the time), and then the randomaccessfile will keeping reading accordingly,when it is 03:00,the last task is not completed,but a new task should start,how to control this?
Similar Messages
-
Further info needed on the System Time Problem when using Bootcamp
Hi, my query is an extension on the previously reported problems and fix with the Sytem Time being incorrect when using Bootcamp.
As respected user 'SideStepSociety' very helpfully pointed out and posted in another thread, the cure for this problem is as follows:-
In Windows, try this:
Run > RegEdit
Find: HKEYLOCALMACHINE > SYSTEM > CurrentControlSet > Control > TimeZoneInformation
Add key ( REG_DWORD type ): RealTimeIsUniversal
Double-click and set value to 1
However, unless I'm mistaken I have seen somewhere that the key type 'REG_DWORD' is 32-bit based and I am running Windows 7 x64 (64-bit) Bootcamp, therefore do I have to enter the QWORD 64-bit type key i.e. 'REG_QWORD' instead of the DWORD 32-bit type key i.e. 'REG_DWORD', or is it perfectly acceptable and fine to just enter both to cover myself should any of the components revert from 64-bit to-32 bit? ..which I have experienced happening once with Windows 'Gadgets' which normally always runs 64-bit, but once reverted to 32-bit.
Advice appretiated, thanks.Thanks for advice.
I had gone ahead and entered the DWORD value in the registry just after my post and a couple of week booting between the two OS's, there were no more problems with the time issue between OS X and Bootcamp.
Shame this most frustrating of little problems where not resolved in a Bootcamp update patch, I had been experiencing this problem for a long, long time not knowing how to fix it and thinking it was my own MacBook Pro that was at fault. I do sympathise now with the possible hundreds or even thousands of Mac-Bootcamp users that are suffering this unbeknown that there's only a special registry fix that has to be manually applied to cure the problem. This is Tacky. I do wonder about Apple sometimes. -
Hi all, I bought one iphone and 3 ipads, i set up all on one apple ID. Now i have a problem when using messages: when sending message from one device it appears again on screen from the other 3 devices. I need help on how to set up messages on each device separately and to start using messages app on each device independently. Thanks
search google for "iphone remove picture from contact"
-
i tried everything in this article, but still have the same problem when using Rapidweaver software. NOT with other software. I am converting my iWeb site to Rapidweaver, whenever there is a calmer period in my office. I have 16 Gb RAM on my NEW iMac and have Parallels desktop, mail, safari, iWeb and Rapidweaver running simultanious.
I never have the problem if i don't use Rapidweaver, but after i have added several pages to Rapidweaver, the problem begins. my iMac won't start up. the only thing that works is re-installing Macos OS X 10.8. i tried even whiping the completeharddrive, and reinstalling with a complete new user, the same problem.
I had it on my previous iMac also, and bought a new one because i thought the problem was in the iMac first. i hadn't noticed it only happens with using rapidweaver.
i sent my complete rapidweaver project to the programmers from rapidweaver at Realmacsoftware, but they couldnt reproduce my problem, there macs started up without any problem.
i deleted all the rapidweaver addons and extra stacks, and started a complete new project.
saterday i had the problem again, after adding about 5 new pages to my rapidweaver site.
i think i have reinstalled Macos OS X 10.8.2 20 or 30 times by now
does anyone have a sollution?Type '''about:support''' in the URL bar and hit Enter.
Scroll down almost to the bottom of that listing and see if you have '''user.js Preferences''' just above the '''''Graphics''''' category.
If you do have that, click on '''user.js file''' in this sentence. <br />
''Your profile folder contains a user.js file, which includes preferences that were not created by Firefox.''
Does that "different homepage" appear in that user.js file? -
I have problems when using the camera on my iPhone 4S (the same for my daughter with a iPhone4)
A veil around the blurred photo, a development impossible and completely unable to read the bar code or QR code. What to do?Sounds kind of stupid, but check to make sure that your iphone case cover is not blocking the edge of the camera lens. I had a silicone case on my 3S and when it got older, it started tot slip and the edges of my pictures were blurred.
-
When writing an e-mail directly on the Orange e-mail service (not on Thunderbird) I am facing the following problem : some distribution lists cannot be used to complete the adressees. The same lists can be used without difficulty if I use Internet Explorer instead of Firefox. The Orange hotline told me that probably my Firefox version was not updated. Unfortunately I checked that, and apparently the automatic updating works. I have also updated the plug ins, without any result.
Please could you specify which webpage you mean ?
The process with Orange is the following :
- 1. click on "Write an e-mail" on the mail webpage
- 2. click on "To" to reach the Contacts which opens a new window
- 3. click on "Distribution lists"
- 4. click on the selected list then click on "add". The list appears ot the box corresponding to the addresses .
UNTIL THEN EVERYTHING WORKS WELL
- 5. click on the button "validate", which closes the window previously opened and normally
- 6. reloads the initial page with the complete list on the line "To". Instead of that I get the last e-mail address I previously used .
Question : at which step of this process should I try your suggestions ? I tried when the initial page was reloaded with the wrong address, but it did not work to get back the rignt distribution list;
Note that the whole process functions with OTHER Distribution lists. The only difference is that the problematic one has a larger number of adresses (62) however inferior to the maximum indicated by Orange (100).
I also remind that there is no problem when using Internet Explorer instead of Firefox.
Thanks for your help ! -
I have, for a couple of months now, experienced a freeze up, and the firefox not responsive when using a date search box like when trying to pick a date for getting a hotel room or booking a rental car. I noticed that I had a message box that had been coming up telling me about unresponsive script detailing something like chrome/calendar/minimonth. I could not find that in my computer anywhere. It happens with ie as well. Any thoughts? This is driving me crazy.
Klaus,
Thanks although you didn't know the answer somebody out there did and I cannot believe how simple the issue was - assign a name to the computer through System Preferences>Sharing
excellent result, it's really nice to stop banging my head against that brick wall
Stuart Mcf -
ORA-01403: no data found Problem when using AUTOMATIC ROW FETCH to populate
ORA-01403: no data found Problem when using AUTOMATIC ROW FETCH to populate a form.
1) Created a FORM on EMP using the wizards. This creates an AUTOMATIC ROW FETCH
TABLE NAME - EMP
Item Containing PRIMARY KEY - P2099_EMPNO
Primary key column - EMPNO
By default the automatic fetch has a ‘Process Error Message’ of ‘Unable to fetch row.’
2) Created a HTML region. Within this region add
text item P2099_FIND_EMPNO
Button GET_EMP to submit
Branch Modified the conditional branch created during button creation to set P2099_EMPNO with &P2099_FIND_EMPNO.
If I then run the page, enter an existing employee number into P2099_EMPNO and press the GET_EMP button the form is populated correctly. But if I enter an employee that does not exist then I get the oracle error ORA-01403: no data found and no form displayed but a message at the top of the page ‘Action Processed’.I was expecting a blank form to be displayed with the message ‘Unable to fetch row.’
I can work around this by making the automated fetch conditional so that it checks the row exists first. Modify the Fetch row from EMP automated fetch so that it is conditional
EXIST (SQL query returns at least one row)
select 'x'
from EMP
where EMPNO = :P2099_EMPNO
But this means that when the employee exists I must be fetching from the DB twice, once for the condition and then again for the actual row fetch.
Rather than the above work around is there something I can change so I don’t get the Oracle error? I’m now wondering if the automatic row fetch is only supposed to be used when linking a report to a form and that I should be writing the fetch process manually. The reason I haven’t at the moment is I’m trying to stick with the automatic wizard generation as much as I can.
Any ideas?
Thanks PeteHi Mike,
I've tried doing that but it doesn't seem to make any difference. If I turn debug on it shows below.
0.05: Computation point: AFTER_HEADER
0.05: Processing point: AFTER_HEADER
0.05: ...Process "Fetch Row from EMP": DML_FETCH_ROW (AFTER_HEADER) F|#OWNER#:EMP:P2099_EMPNO:EMPNO
0.05: Show ERROR page...
0.05: Performing rollback...
0.05: Processing point: AFTER_ERROR_HEADER
I don't really wan't the error page, either nothing with the form not being populated or a message at the top of the page.
Thanks Pete -
Problem when using About Operator in Contains Query
Hi,
I'm new to Oracle and this forums too. I have a problem when using about operator in contains query.
I create a table with some records and then create a context index on 'name' column.
CREATE TABLE my_items (
id NUMBER(10) NOT NULL,
name VARCHAR2(200) NOT NULL,
description VARCHAR2(4000) NOT NULL,
price NUMBER(7,2) NOT NULL
ALTER TABLE my_items ADD (
CONSTRAINT my_items_pk PRIMARY KEY (id)
CREATE SEQUENCE my_items_seq;
INSERT INTO my_items VALUES(my_items_seq.nextval, 'Car', 'Car description', 1);
INSERT INTO my_items VALUES(my_items_seq.nextval, 'Train', 'Train description', 2);
INSERT INTO my_items VALUES(my_items_seq.nextval, 'Japan', 'Japan description', 3);
INSERT INTO my_items VALUES(my_items_seq.nextval, 'China', 'China description', 4);
COMMIT;
EXEC ctx_ddl.create_preference('english_lexer','basic_lexer');
EXEC ctx_ddl.set_attribute('english_lexer','index_themes','yes');
EXEC ctx_ddl.set_attribute('english_lexer','theme_language','english');
CREATE INDEX my_items_name_idx ON my_items(name) INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS('lexer english_lexer');
EXEC ctx_ddl.sync_index('my_items_name_idx');Then I perform contains query to retrieve record :
SELECT count(*) FROM my_items WHERE contains(name, 'Japan', 1) > 0;
COUNT(*)
1
SELECT count(*) FROM my_items WHERE contains(name, 'about(Japan)', 1) > 0;
COUNT(*)
1But the problem is when I using ABOUT operator like in Oracle's English Knowledge Base Category Hierarchy it return 0
SELECT count(*) FROM my_items WHERE contains(name, 'about(Asia)', 1) > 0;
COUNT(*)
0
SELECT count(*) FROM my_items WHERE contains(name, 'about(transportation)', 1) > 0;
COUNT(*)
0I can't figure out what 's wrong in my query or in my index.
Any help will be appreciated.
Thanks,
Hieu Nguyen
Edited by: user2944391 on Jul 10, 2009 3:25 AMHello (and welcome),
You'd be best asking this question in the Oracle Text forum, here:
Text
And by the way, it will help others to analyse if you put {noformat}{noformat} (lowercase code in curly brackets) before and after your code snippets.
Good luck! -
Photoshop CS6 crashes all the time and especially when using the type tool... please help!
Since I did not have this problem with CS5 or CS4, I can only assume something is not right with Photoshop CS6... below is my video card info:
ATI Radeon HD 4850:
Chipset Model: ATI Radeon HD 4850
Type: GPU
Bus: PCIe
PCIe Lane Width: x16
VRAM (Total): 512 MB
Vendor: ATI (0x1002)
Device ID: 0x944a
Revision ID: 0x0000
ROM Revision: 113-B9110C-425
EFI Driver Version: 01.00.383
Displays:
iMac:
Resolution: 2560 x 1440
Pixel Depth: 32-Bit Color (ARGB8888)
Main Display: Yes
Mirror: Off
Online: Yes
Built-In: Yes
Connection Type: DisplayPort
Cinema HD:
Resolution: 1920 x 1200
Pixel Depth: 32-Bit Color (ARGB8888)
Display Serial Number: 2A80273WXMN
Mirror: Off
Online: Yes
Rotation: Supported -
When using FireFox I often cannot view pictures in Hotmail emails, but I have no problem when using other browsers
Do you also have this issue if you temporarily switch to Private Browsing mode?
*https://support.mozilla.org/kb/Private+Browsing
*Tools > Options > Privacy, choose the setting <b>Firefox will: Use custom settings for history</b>
*Select: [X] "Always use private browsing mode"
Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
*Don't make any changes on the Safe mode start window.
*https://support.mozilla.org/kb/Safe+Mode
*https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
See also:
*https://support.mozilla.org/kb/fix-login-issues-on-websites-requrie-passwords -
Coercion problem when using Shared Variable
I have a curious coercion problem when using Shared Variables. I want to share the state of a State Machine, which is an enum saved as a control (typedef) called TYPE State (see attached). I create a shared variable called State and define it as a Custom Control, using the just-mentioned typedef. So far, so good. I've attached three simple VIs -- the first one, Init State, simply wires a constant to the input of the Shared Variable to initialize it -- the wired constant is, of course, defined by the typedef. However, the Get State and Set State, meant to wire an indicator (for reading the state) or control (for setting it), develop coercion dots when wired into the Shared Variable. Why? How do I get rid of the dot? [I suppose I could abandon my typedef and custom control, but the beauty of typedefs and custom controls is that it "enforces" rules, lets you use enums for clarity, keeps the code "honest", etc. -- I'd hate to give that up just to get rid of a dot!].
On a related note, the code seems to work. This is much too simplistic to do anything, but if you open Set State and Get State, set the state to anything, run it (it immediately stops, of course), then run Get State, you'll see the chosen state appear in the indicator. So it does appear to work. The "error" (coercion dot) may, I suppose, be a "bug" in Labview because it can't figure out the mapping of the (very simple!) Custom Control, but if so, I hope it gets fixed quickly!
Bob Schor
Attachments:
Coercion Problem1.zip 38 KBHello Bob,
I am also seeing this behavior, I will escalate this question to our LabVIEW developers and post again here no later than next Tuesday, November 27th as National Instruments will be closed for the remainder of this week.
If this issue does turn into a product suggestion, I would suspect the workaround would to live with the coersion dot for the time being.
Enjoy the holiday
Regards,
Erik J.
Applications Engineer
National Instruments -
NLS support problems when using AL32UTF8 in dads.conf
Hello,
Following a post by Joel Kallman, in one of the forum threads, about the mandatory use of AL32UTF8 in dads.conf, when running HTML DB v2.0, I changed my PlsqlNLSLanguage parameter accordingly.
Prior to the change, I experienced some problems when using non-English characters some application items appeared as gibberish when contained non-English characters, and the LIKE operator didn't perform as expected. After the change, it all seems to work OK, but now I have a different problem.
All the non-English characters in my HTML page source code appears as gibberish. On screen, at run time, everything display correctly, but the source code seems to be corrupted. It is very difficult, and very annoying to debug the pages that way. Is there a way to enjoy both worlds Using AL32UTF8 in the dads.conf, as required, and still getting a coherent HTML source code, containing non-English characters?
Thanks,
Arie.Joel,
I use the following settings and they work fine for me:
Operating system:
LANG=de_DE
LANGVAR=de_DE.UTF-8
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
daust:oracle[o1020]> uname -a
Linux daust.opal-consulting.de 2.4.21-37.EL #1 Wed Sep 7 13:35:21 EDT 2005 i686 i686 i386 GNU/Linux
daust:oracle[o1020]> cat /etc/redhat-release
Red Hat Enterprise Linux ES release 3 (Taroon Update 6)
daust:oracle[o1020]>
marvel.conf:
<Location /pls/htmldb>
Order deny,allow
PlsqlDocumentPath docs
AllowOverride None
PlsqlDocumentProcedure wwv_flow_file_manager.process_download
PlsqlDatabaseConnectString localhost:1521:o1020
PlsqlNLSLanguage AMERICAN_AMERICA.WE8ISO8859P1
PlsqlAuthenticationMode Basic
SetHandler pls_handler
PlsqlDocumentTablename wwv_flow_file_objects$
PlsqlDatabaseUsername HTMLDB_PUBLIC_USER
PlsqlDefaultPage htmldb
PlsqlDatabasePassword @BZvJYqadreElOqj5poCB5gE=
Allow from all
</Location>
Database:
daust:oracle[o1020]> sqlplus "/ as sysdba"
SQL> select * from nls_database_parameters;
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET WE8ISO8859P1
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
PARAMETER VALUE
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 10.2.0.1.0####################
Using AL32UTF8 resulted in the same problem as described ( and fixed ) here: Re: Strange - HTML not written correctly
So, what is the proper configuration of the DAD, perhaps there are different ones for Unicode instances and non-Unicode instances.
~Dietmar. -
Performance problem when using CAPS LOCK piano input
Dear reader,
I'm very new to Logic and am running into a performance problem when using the CAPS LOCK-piano-keyboard for input of an instrument: when I'm not recording everything is fine and the program instantly responds on my keystrokes, but as soon as I go into record-mode there is sometimes a delay in the response-time (so I press a key and it takes up to half a second longer before the note is actually played).
Is there anything to do about this to improve performance (for example turning of certain features of the application), or should I never use the CAPS LOCK keyboard anyway and go straight for an external MIDI-keyboard?
Thanks and regards,
Tim MetzDoes your project have Audio tracks and just how heavy it is, how many tracks? Also, what kind of Software Instrument do you use?
-
We use IE9.
I enter in https://gwserver.
Compose New mail (in Plain Text mode) with body:
Line-1
Line-2
Line-3
And send this mail , for example to itself.
the received letter will look like:
Line-1Line-2Line-3
Someone has the same problem?
SergAre you guys still on the shipping code of GW 12? Novell had a fix for this within a couple weeks of GW 12 being released from what I remember. Open an SR and get the latest code.
Or simply tell your users to user HTML.
Todd Bowman
Todd Bowman
Senior Network Analyst
University of Minnesota Physicians
612-884-0744
[email protected]
>>>
From: MarkDissington<[email protected]>
To:novell.support.groupwise.2012.web-access
Date: 5/24/2012 6:46 AM
Subject: Re: Problem when using IE9
skoltogyan;2197344 Wrote:
> The solution is?
>
> Serg
I would guess don't use IE9 until a fix is released? :-)
M.
MarkDissington
MarkDissington's Profile: http://forums.novell.com/member.php?userid=27611
View this thread: http://forums.novell.com/showthread.php?t=455634
Maybe you are looking for
-
How can I link Apple TV (Gen1) to Time Capsule (Gen 4)?
Everyone I am using a the above mentioned Time Capsule as privat WiFi Network for our devices at home (MacBook Pro, iPhones & iPads). The Time Capsule itself is connected to a DSL Modem by means of an ethernet cable. So far so good. Newly I have got
-
With Flash Professional 8, can I import or attach a standard PDF file to a flash document so that it can be downloaded off the web?
-
ICloud doesn't show up in Numbers open file dialog box
How do you add iCloud to the Numbers open file dialog box? It doesn't show up for me. I've already set up iCloud in my system preferences and enabled document synching.
-
How do I increase the font size on the web page?
The font on Safari page is too small for me. I have tried and could not get it adjusted as in Macbook. Any one who can help? For zooming doesn't resolve the problem.
-
Hi i have an iphone 4s that was brought from U K - it is saying no service??..............would this be because it is blocked ? and any way i can unblock on line?