Is it possible to reuse the Scanner instance in this case?

I have a data file that gets updated by another process, and in my program I periodically read the file, and if there'S new data added I will update my data structure (contained in ArrayLists).
The issue is for every read I have to re-create a Scanner instance and skips all the lines that have been read. Since the file could get really long, and to skip lines in the file we need still to call scanner.readLine() which might be expensive since it interacts with the hard disk, I'm trying to reuse the Scanner instance and count on the scanner.hasNextLine() to return true if new lines are inserted to the file by the other process:
while (in.hasNextLine()) {
String line = in.nextLine();
// intepret th eline here
This code is put in a Runnable that is executed periodically, and I was hoping that the next time it is called in.hasNextLine() would return true and we can happily start where we were left off.
But the bloody method does NOT return true even though new lines have been added to the file. Does anyone know to make it recognize that the file has been updated? Or really there's no other way but to re-open the file and skip old lines as I'm doing now?
Any suggestion would be highly appreciated!
P.S: How could I add code tags to highlight my code portion? Thanks!

808239 wrote:
I have a data file that gets updated by another process, and in my program I periodically read the file, and if there'S new data added I will update my data structure (contained in ArrayLists).Is there any reason you can't use a Stream instead of a file? Unix has a nice little utility called 'tee' that allows you to write out to a file AND stdout, allowing you to connect other commands via a pipe. I'm sure you could write something similar for Java; however, if this is intended as a daemon process, you'd probably have to make it non-blocking, which might be an issue.
Alternatively, have you considered using a database instead of a file?
Winston

Similar Messages

  • I have a problem with my iphone,after upgrade software ios 6.0.1,  is not possible to use the wi-fi, used until now, because is not possible to have the login, i find this message " the requested URL  was not found

    I have a problem with my iphone,after upgrade software ios 6.0.1,  is not possible to use the wi-fi, used until now, because is not possible to have the login, i find this message " the requested URL  was not found

    You have to go to autherized iPhone agent.

  • Is it possible to change the database instance host ??!!

    Hello,
    Quick question, I finished the installation of XI 3.0 with all patches.  But the system is running low, very low on resources even though it has 2GB of RAM.  I was wondering if it is possible to migrate the <SAPID> database and then re-configure the central instance and J2EE Engine to access a different machine OR do I have to re-install and follow the distributed system installation process.
    Thanks!

    Diego--
    Your issue isn't the database, it's the J2EE server.  Moving the database instance isn't going to save you enough RAM -- you'll run into the same problem again as soon as you start running messages through the system, when the J2EE engine starts allocating heap space for those messages.
    Our experience has been that 2GB of RAM is not enough for a development/prototype XI system.  You need 3GB to do a basic prototype/development machine install (but ask for 4GB if this is your permanent development system).  You'll need more than that in a typical production system.
    --Dan King
    Capgemini

  • What is the best practice in this case?

    I want to create a vending machine simulation program.
    The design will be something like this :
    GUI----use----VendingMachine----has----ProductStorage
    Previously, i want everything inside VendingMachine will be transparent from the GUI.
    The GUI just use VendingMachine, and it has no knowledge about ProductStorage.
    But then i realize that in order for the GUI to display the products, it has to use ProductStorage.
    So i came up with adding this getter to VendingMachine class :
    public ProductStorage getStorage()
         return storage;
    }I'm breaking the rules of encapsulation.
    Is it okay to do this? What is the practice in this case?
    Thanks,
    Ang.

    GUI----use----VendingMachine----has----ProductStorage
    Previously, i want everything inside VendingMachine will be transparent from the GUI.
    The GUI just use VendingMachine, and it has no knowledge about ProductStorage.
    But then i realize that in order for the GUI to display the products, it has to use ProductStorage.Not necessarily. You can expose the ProductStorage interface (did I get this right: methods such as getProductList(), getProductQuantity(String productId) ?), in VendingMachineImpl. That latter can simply delegates to its ProductStorage collaborator. The GUI code doesn't need to know this latter is a separate instance.
    I'm breaking the rules of encapsulation.
    Is it okay to do this? What is the practice in this case?Technically you're violating the so-called Law of Demeter, which as you mention means you reveal implementation details to the client - and makes it less flexible, if you ever want to move ProductStorage API in another class. For example it would exhibit transaction logic to the client code.
    OK we're talking about a far-fetched exemple, part of an exercise, but in general you should avoid this.

  • Wich way does the synchronization go in this case?

    Hi!
    I got the damaged itunes library thing a few days ago and can't copy over the new one with the damaged one.
    Thing is, i synchronized the ipod a few days before the disaster. So i am wondering, as i got everything in the same location, if i erase the playlist and put all songs in itunes like a fresh start, can i then plug in the ipod to get the ratings etc. to itunes, or will the ipod get the same data as the fresh itunes library AKA deleted ratings etc? As i said, all the songs on the computer is in the same location.

    Ratings, last played, last skipped, play counts, current position, link to downloaded art(?) and probably a few other bits of data live only in the library. If your library is trashed & you rebuild then syncing to the iPod would delete the information rather than bringing it back to iTunes. It may be possible to recover some of this metadata using one of the tools referenced in this post from Zevoneer:
    http://discussions.apple.com/thread.jspa?messageID=6273675&#6273675
    tt2

  • How can I use the onmouseover event in this case?

    Hello!
    Sorry If it's a simple question... I'm a beginner in JSFs :P...
    I need to do with a dataTable an effect.
    In my old JSP file (Basically made with HTML), when I made a TABLE, I changed the class of all the rows. Like this:
    <TABLE>
    <TR onmouseover="this.className='OnStyle'" onmouseout="this.className='OffStyle'">
    <TD>...</TD><TD></TD>
    </TR>
    </TABLE>All the row changes if the mouse was pointing at its.
    How can i do this with a simple dataTable? I have only 2 colums and a few rows :(
    Thanks a lot!

    Apparently JSF does not provide as simple solution to this simple task as one would expect. I've been looking for a solution to it myself but not found an answer.

  • What is the public IP in this case?!!

    I have an ASA firewall,i also have a Motorola router that is actually a modem and a router and an access point in the same time (3 in 1) ;however iam only intending to use the Motorola internal ports to connect to the external ASA port, when i finish the NAT rules (which translating the internal ASA network into the outside network which is 192.168.0.0/24 which is the internal network for the Motorola router) which one is the public IP address in this case?? i mean i might not be able to get to the ASA's internal IP from the Internet because it is the internal network for the Motorola...so in this case is my only public IP on the Internet in the Motorola's external IP ? which is the ISP's IP address provided???
    I am really lost on this one, any help here is much appreciated.
    Thanks

    Hi,
    Seems to me that your public IP address will be configured on the Motorola device. In most cases the device will probably be using DHCP to get the public IP address from the ISP and therefore the IP might sometimes change. Though naturally it might be a static public IP address as I don't know the thing is handled in your case.
    If you wish to have a host/server reachable from the Internet then you would probably have to configure somekind of Static PAT (Port Forward) on the Motorola device or perhaps even Static NAT the public IP address from to the external IP of the ASA (from the network 192.168.0.0/24) so that all traffic that is allowed on the Motorola device will be forwarded to the ASA (because of the 1:1 Static NAT mapping of the IP addresses)
    If you need to reach your internal network remotely and dont need to host anything directly to the public network then you might be able to set up VPN Client connection to the ASA.
    If you dont know the public IP address then if its a DHCP IP address from the ISP you can always check your current public IP address through some site. I for example tend to go to www.ripe.net . It shows your current IP address on the site. Naturally there should be multiple other sites that show this information.
    If your public IP address is static then the ISP probably has provided you some documentation which mentions the public IP address assigned to you when you got the Internet connection.
    Also you might not need to configure NAT at all on the ASA since its not an edge device. You could simply let the internal networks of ASA and the Motorola device to communicate with their original IP addresses. This would naturally require that the Motorola device has a route for the ASA internal network on it pointing towards the external IP address of the ASA.
    - Jouni

  • It is possible to reuse the obfuscated password from a dads.conf in the apex listener?

    Hello there,
    Little by little we are moving to the APEX 2 listener, good! But the problem is that every time that somebody ask me for a new set up I have the same problem:
    I go to one of our DBAs (nice guys by the way!) and ask, "may I have the password for the APEX_PUBLIC_USER of this DB"?
    The password is obfuscated, so the answer is: it needs to be changed => delay in the setup => unhappy users...
    I have tried a classic copy and paste, this is take the obfuscated password from the dad and put it in the <entry key="db.password">, but of course it did not work, sigh...
    Any thoughts on this?
    Thanks in advance,
    Luis

    If you are using adobe Flex Builder to develop SWF, please be sure using ExternalInterface class to expose the refresh() method.
    then you can should be able to call this method in Javascript.

  • Is it possible to reuse the map file that was produced to map FrameMaker styles to RoboHelp when creating a PDF in RoboHelp?

    I'm using RoboHelp 11 to produce WebHelp. The documentation was previously written in FrameMaker and posted in PDF format, however it has undergone many releases since those days. I'm now being asked to create the help in PDF and WebHelp. Not really an issue except that the help format does not look particularly good in PDF (not designed for both).
    Ideally I'd like to just use the map file from the original Frame to RoboHelp conversion in reverse (with a little editing)--to convert the RoboHelp styles to the original FrameMaker formats when I create the PDF, however A) there doesn't seem to be an option for that, and B) the original FrameMaker to RoboHelp map file doesn't seem to have been preserved after that conversion.  Is it there and I'm just not seeing it?
    If necessary I can just create another CSS to redefine the styles, but if I don't have to, I rather not.

    I suspect that even if you could find the mapping information (pass as to where) it would simply tell you that Style A in Fm was mapped to Style B in Rh but not give you any information about how Style A was defined in Fm.
    I think your only options are to create a CSS as you suggest or, as I would, create redefine the Word Style Mapping Template to suit. By going to Word first, you can edit the output for better page breaks and other tweaking you might want.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • MP navigator ex the scanner driver for this device is not supported for my itunes/ ipod

    Mp navigator ex driver for this device not supported when I plug in my ipod I have windows vista

    Hello there K_McCreedy,
    I saw your post about the scanning issues you have been having with your PS B110a and Mavericks. I have looked into this for you and I would like to offer some suggestions.
    First of all, there is no downloadable full feature driver and software (scanning software included) for this model of printer and Mavericks. There are some work around options however, that I will link you to below!
    Please follow these steps:
    1. Mac OS X: How to reset the printing system
    2. Repair disk permissions
    3. OS X v10.9 Mavericks: Installing and Using the Printer on a Mac
    (See under link #3 for the different methods of scanning options with Mavericks under the FAQ's section)
    I hope I helped answer your question!
    Thanks for posting in the community and have a great day
    R a i n b o w 7000I work on behalf of HP
    Click the “Kudos Thumbs Up" at the bottom of this post to say
    “Thanks” for helping!
    Click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution!

  • I have a digital copy of harry potter and the daethly hallows part 1 on my pc and ipod touch, is it possible to get the iTunes extras for this movie without buying it off iTunes?

    is there any way of helping me out please

    There is no limit to the number of iPods you can sync to one computer, iTunes library, or account. 
    You might want to create a seperate iTunes library for him, perhaps on another user account on the system and move all of his Jazz music over to that new library.  Once you have all of his music moved over to his own library, remove it from your own and then resync both of your iPods to clear his music off.  This is just one way to do it.
    If that was a bit confusing, take a look at this article for a few ways to manage multiple iPods with one computer.
    How to use multiple iPods, iPads, or iPhones with one computer
    B-rock

  • Coalesce or compress this index? what is the best solution in this case?

    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64biI have executed the following query on a specific index that I suspected to be smashed and got the following result
    select
        keys_per_leaf, count(*) blocks
    from (  
          select   sys_op_lbid (154813, 'L', jus.rowid) block_id,
                 count (*)                            keys_per_leaf
          from xxx_table jus
           where jus.id is not null
                  or jus.dat is not null
          group by sys_op_lbid (154813, 'L', jus.rowid)
    group by keys_per_leaf
    order by keys_per_leaf;
    keys_per_leaf     blocks 
    1     80       
    2     1108       
    3     2816       
    4     3444       
    5     3512       
    6     2891       
    7     2579       
    8     2154       
    9     1943       
    10     1287       
    11     1222       
    12     1011       
    13     822       
    14     711       
    15     544       
    16     508       
    17     414       
    18     455       
    19     425       
    20     417       
    21     338       
    22     337       
    23     327       
    24     288       
    25     267       
    26     295       
    27     281       
    28     266       
    29     249       
    30     255       
    31     237       
    32     259       
    33     257       
    34     232       
    35     211       
    36     209       
    37     204       
    38     216       
    39     189       
    40     194       
    41     187       
    42     200       
    43     183       
    44     167       
    45     186       
    46     179       
    47     179       
    48     179       
    49     171       
    50     164       
    51     174       
    52     157       
    53     181       
    54     192       
    55     178       
    56     162       
    57     155       
    58     160       
    59     153       
    60     151       
    61     133       
    62     177       
    63     156       
    64     167       
    65     162       
    66     171       
    67     154       
    68     162       
    69     163       
    70     153       
    71     189       
    72     166       
    73     164       
    74     142       
    75     177       
    76     148       
    77     161       
    78     164       
    79     133       
    80     158       
    81     176       
    82     189       
    83     347       
    84     369       
    85     239       
    86     239       
    87     224       
    88     227       
    89     214       
    90     190       
    91     230       
    92     229       
    93     377       
    94     276       
    95     196       
    96     218       
    97     217       
    98     227       
    99     230       
    100     251       
    101     266       
    102     298       
    103     276       
    104     288       
    105     638       
    106     1134       
    107     1152     
    229     1       
    230     1      This is a 5 columns unique key index on (id number, dat date, id2 number, dat2 date type number).
    Furthermore, a space analysis of this index using dbms_space.space_usage gives the following picture
    Number of blocks with at least 0 to 25% free space            = 0                   -------> total bytes = 0
    Number of blocks with at least 25-50% free space              = 75                 -------> total bytes = ,5859375
    Number of Blocks with with at least 50 to 75% free space  = 0                   -------> Total Bytes = 0
    number of blocks with at least 75 to 100% free space        = 0                   -------> total bytes = 0
    Number of full blocks with no free space                              = 99848           -------> total bytes = 780,0625
    Total blocks ______________________________
    99923
    Total size MB______________________________
    799,384It seems for me that this index needs to be either coalesced or compressed.
    Then, what would be the best option in your opinion?
    Thanks in advance
    Mohamed Houri
    Edited by: Mohamed Houri on 12-janv.-2011 1:18

    So let me continue my case
    I first compressed the index as follows
    alter index my_index rebuild compress 2;which immediately presents two new situations
    (a) index space
    Number of blocks with at least 0 to 25% free space    = 0                -------> total bytes = 0
    Number of blocks with at least 25-50% free space      = 40              -------> total bytes =, 3125
    Number of Blocks with at least 50 to 75% free space   = 0                -------> total Bytes = 0
    Number of blocks with at least 75 to 100% free space  = 0                -------> total bytes = 0
    Number of full blocks with no free space                = 32361           -------> total bytes = 252, 8203125
    Total blocks ______________________________
    32401
    Total size Mb______________________________
    259,208meaning that the compress command freed up 67487 leaf blocks and reduced the size of the index from to 799,384 MB to 259,208 MB.
    It also shows a relative nice pictue of number of keys per leaf block (when compared to the previous situation)
    (b) on the number of key per leaf block
    KEYS_PER_LEAF     BLOCKS       
    4     1       
    6     1       
    13     1       
    15     1       
    25     1       
    62     1       
    63     1       
    88     1       
    97     1       
    122     1       
    123     3       
    124     6       
    125     4       
    126     2     
    289     4489       
    290     3887       
    291     3129       
    292     2273       
    293     1528       
    294     913       
    295     442       
    296     152       
    297     50       
    298     7       
    299     1      In a second step, I have coalesced the index as follows
    alter index my_index coalesce;which produces the new figure
    Number of blocks with at least 0 to 25% free space     = 0          -------> total bytes = 0
    Number of blocks with at least 25-50% free space      = 298        -------> total bytes = 2,328125
    Number of Blocks with at least 50 to 75% free space   = 0           -------> Total Bytes = 0
    Number of blocks with at least 75 to 100% free space = 0            -------> total bytes = 0
    Number of full blocks with no free space = 32375                    -------> total bytes = 252, 9296875
    Total blocks ______________________________
    32673
    Total size MB______________________________
    261,384meaning the the coalesce command has made
    (a)     298-40 = 258 new blocks with 25-50% of free space
    (b)     32375-32361 = 14 new additional blocks which have been made full
    (c)     The size of the index increased by 2,176MB (261,384-259,208)
    While the number of key per leaf block keeps in the same situation
    KEYS_PER_LEAF     BLOCKS       
    4     2       
    5     3       
    9     1       
    10     2       
    12     1       
    13     1       
    19     1       
    31     1       
    37     1       
    61     1       
    63     1       
    73     1       
    85     1       
    88     1       
    122     1       
    123     4       
    124     4       
    125     3       
    126     1     
    289     4492       
    290     3887       
    291     3125       
    292     2273       
    293     1525       
    294     913       
    295     441       
    296     152       
    297     50       
    298     7       
    299     1      Could you please through some light on the difference between the compress and the coalesce on the effect they have made on
    (a) the number of keys per leaf blocks within my index
    (b) the space and size of my index?
    Best regards
    Mohamed Houri

  • Why did you change the ipad to that crappy lightning cord.it does not stay plugged in to ipad to use it on ac power the cords short and overheat damaging the charger units. please change back to the old style.in this case newer is definately not better

    anyone else think the lightning cord as a piece of garbage

    I agree. It's much better than the old one.
    If your have a problem with something overheating, that's not normal. You should take the charger, cable and iPad to the nearest Apple Store. Is the charger an Apple charger or a third party one? Many of the third party chargers are badly made.

  • My 16 months old MacBook Pro just got out of battery and turned off in the normal way in this cases. After conecting it to the electricity, I turned it on again and then after restoring the sistem went off and its not working anymore!!!

    I tried pressing at the same time ctrl shift comand keys to reset it and then when I try to turn it on again it just starts the screen blinks and the hard drive sounds briefly but then it dead, if you close the mac then the light that glows when is sleepeng turns on and the computer gets hot and the fans turns on and it´s stopped when the battery is dead again.
    Please help its incredible, it´s my 3 mac and I never experienced this before.

    Thanks Sig. The information is here: Anything useful stand out?
    Battery Information:
      Model Information:
      Serial Number:    9G1130CJVD3MA
      Manufacturer:    DP
      Device Name:    bq20z451
      Pack Lot Code:    0000
      PCB Lot Code:    0000
      Firmware Version:    0201
      Hardware Revision:    0002
      Cell Revision:    0158
      Charge Information:
      Charge Remaining (mAh):    5663
      Fully Charged:    Yes
      Charging:    No
      Full Charge Capacity (mAh):    5663
      Health Information:
      Cycle Count:    59
      Condition:    Normal
      Battery Installed:    Yes
      Amperage (mA):    261
      Voltage (mV):    12574
    System Power Settings:
      AC Power:
      System Sleep Timer (Minutes):    10
      Disk Sleep Timer (Minutes):    10
      Display Sleep Timer (Minutes):    10
      Wake on AC Change:    No
      Wake on Clamshell Open:    Yes
      Wake on LAN:    Yes
      Current Power Source:    Yes
      Display Sleep Uses Dim:    Yes
      Battery Power:
      System Sleep Timer (Minutes):    10
      Disk Sleep Timer (Minutes):    10
      Display Sleep Timer (Minutes):    2
      Wake on AC Change:    No
      Wake on Clamshell Open:    Yes
      Display Sleep Uses Dim:    Yes
      Reduce Brightness:    Yes
    Hardware Configuration:
      UPS Installed:    No
    AC Charger Information:
      Connected:    Yes
      ID:    0x0100
      Wattage (W):    60
      Revision:    0x0000
      Family:    0x00ba
      Serial Number:    0x00262704
      Charging:    No

  • SCORM: Why not write the API Instance in ActionScript

    We're working on a SCORM compliant system for a major blue
    chip. We have a mixture of old AS1 and AS2 content, along with
    shiny new AS3 modules, all of which needs to be intergrated into a
    single system. As I have posted about elsewhere here, there seem to
    be some issues with fscommand() and ExternalInterface when content
    from mixed virtual machines is loaded into Flash Player - the
    connection to Javascript just fails silently (even after a
    successful call to ExternalInterface.available ).
    We've been looking, therefore, at simply building an API
    instance in AS3.0, and using robust http calls to communicate from
    there to the LMS. The SCORM specification calls for the API
    Instance to be written using ECMAScript. Every implementation we
    can find seems to equate this with Javascript but my understanding
    (and please correct me if I'm wrong, anyone), is that Actionscript
    is itself an ECMAScript dialect. That being so, it ought, we think,
    to be possible to create the API instance within Flash.
    Does anyone with direct experience of this know if an
    application using an Actionscript API would be SCORM compliant or
    if there is any other way we can avoid using the Flash > JS API
    > LMS channel which has been giving us such problems?
    Many thanks in advance for any responses.
    Jude Fisher
    JcFx Limited
    http://www.jcfx.eu

    I found why: The handler function should take an EffectEvent parameter.

Maybe you are looking for