A question about performance in processing a string

hi all
i have a string that contains some text - few paragraphs. there are two specific words in the string that i need to search and replace with other stuff. my question is that :
is it faster to process one line at a time to search two words(in a loop) or use the indexOf method of the String class to find one word at a time (process the text twice)? i don't really know how quick or efficient the indexOf method is. thanks in advance.

The following program replaces "James" with "Jim" and "William" with "Bill".
class Test111 {
    public static void main(String[] args) {
        String s = "James Gosling, William Gates, William Joy";
        System.out.println (s.replaceAll("\\bJames\\b", "Jim").replaceAll("\\bWilliam\\b", "Bill"));
}It must print "Jim Gosling, Bill Gates, Bill Joy".

Similar Messages

  • Question about sql batch process in java app

    hi all
    i have few questions about using batch process in the java.sql package. the addBatch method can take sql statements like inserts or updates. can we use a mixture of insert and update then? can we use prepared statement for this? it's just for performance consideration. thanks in advance.

    hi all
    i have few questions about using batch process in the
    java.sql package. the addBatch method can take sql
    statements like inserts or updates. addBatch() is a method that has no parameters. It doesn't 'add' sql statements.
    can we use a
    mixture of insert and update then? can we use
    prepared statement for this? it's just for
    performance consideration. thanks in advance.The point of batching is that you take something that is invariant and then 'add' a variant part.
    Thus a single insert has an invariant part (the table and specific columns) and a variant part (the data for each row by column.)
    You can use anything that is valid SQL (for jdbc, driver, database) and use it presuming your database allows that particular usage in batching. But that does require some regular pattern - it won't work if your usage is random. Nor will it work if some statements need to be executed only some of the time. Finally also note that transaction processing will often require smaller chunks - you can't insert a million rows in one batch.

  • A simple question about performance!

    Hi! I have a simple question about performance. Suppouse that you have a servlet or a class with DB access, and you need to use a value several times in that page. What is best, to assign the value from say, a resultset or a request.getParameter() to a variable or to call the resultset or the request every time you need to retrieve that value? Which option uses less memory, which is faster, etc.?
    Hoping the best fou u
    Raul

    If you need more values from a db, the best is to open some connections (connection pool) and use the for accessing the db.
    To get the data only once, open the connection, get the data, store the data whereever you want: variable (class), hidden control (if you want to send from one page to another by request) and close the connection as quicky as possible.
    The advantage of the first method is that the most time consuming activity (connections opening) is done only once.

  • Hi Chris -- follow up to my question about using TSQ to store strings of different sizes

    Thanks for your response.
    I did read about those method you mentioned. I have some troubles with each method:
    1/ Using TSQ as byte stream.
    This is what I chose to use. I basically write to the queue the way you described with an exception about the number of byte to write. I did as followed:
    CmtWriteTSQData (tsqHandle, buffer, strlen (buffer),TSQ_INFINITE_TIMEOUT, NULL);
    with buffer as the buffer containing my string. Note that strlen(buffer) is not same each time. Also a thread is doing the writing to the queue and another thread is doing the reading. This leads to my next question: How do you read these strings out?
    Right now I am reading one
    byte at a time with:
    while (1)
    CmtReadTSQData (tsqHandle, tempbuf, 1, 10, 0);
    in a loop, with tempbuf to contain this single char, and then store it in another buffer until I read out a CR of LF which signals the end of a string.
    Will I have any problem?
    Could you please provide an alternative?
    2/ Using TSQ to contain pointers to strings.
    I haven't tried this method since I think it requires allocation of rather large static array of buffer and also requires keeping track of these pointer in a link list.
    Would you elaborate how you would use TSQ this way in my case.
    3/ Lastly, the way I described in (1) works only if I have the main thread to do writing, and another thread to do reading. Some how it doesn't work when I used one thread to do writing, one thread to do reading, and the main thread to handle user interface. I found out that the program spends all its time in the reading thread (inside the while loop).
    Why is it different if the writ
    ing thread is the main thread? Do I miss something like priority,... or anything like that?
    Thank you so much.

    You really should consider using event driven reading. There is examples of this in the Multithreading examples in cvi\samples\utility\Threading. Then you will get an event in the reader thread whenever a certain number of items are available to read. If you use the byte stream method, you should send the message length with each method so you know how to package the messages back on the reader side.
    For the pointer method, you would malloc the buffer on the writer side, send the pointer to the reader, then the reader would free the memory when it is done with the data.
    I don't understand why what you are describing in 3 occurs. If you aren't setting priority to something other than default, then each thread should get time. If you want to free up time i
    n a thread that is taking to much, just put a small Delay in that thread.
    If you want more help on this, you can look at the examples I mentioned above, read the Multithreading Overview available in PDF form in the cvi\bin directory or contact NI support at http://www.ni.com/ask.
    Best Regards,
    Chris Matthews
    Measurement Studio Support Manager

  • Questions about the load processing of OpenSparc T1 Dcache

    Hi,
    I have some questions about OpenSparc T1 Dcache load processing.
    During load processing, subsequent loads to the same address need to search the store buffer for a valid store to that address. If there is a CAM hit, data is sourced from the store buffer, not from the D-cache, and no load request will be sent to the L2.
    What if there is no CAM hit. Would the load request be sent to L2? Or would Dcache be checked for the requested data?
    If the load request would be sent to L2, what next? Would the Dcache be updated?
    Thanks

    Store buffer is checked for Read after Write (RAW) condition on loads. If there is full RAW - i.e. full data exists in the store buffer - then the data is bypassed and no D cache access happens.
    If RAW is partial (e.g. word store followed by a double word load) then load is treated as a miss. Store is allowed to complete in L2 cache and then load instruction is completed.
    For the miss in STB, D cache is accessed. If hit, data is fetched from D$. If miss, data is fetched from L2$ and allocated in D$.

  • Question about how XI process files in FTP

    Hi experts,
    I have a file-FTP to JDBC scenario.
    XI scans a folder every minute to see if any file has appear.
    My question is, does XI process the files in their order of creation, or randomly ?
    If not, is there a way to make XI process them in order of creation ?
    Thanks a lot, any help would be appreciated.
    Kind regards,
    Jamal

    Hi,
    from SAP Help:
    If you select files from an FTP server and not from the file system, you need to make the following additional specifications:
    ○       ftp.host=<ftp-server>
    The host name or IP address of the FTP server. If this specification is made, it is assumed that you are accessing an FTP server. The specifications file.sourceDir and file.sourceFileName then refer to the FTP server. The following are then not possible specifications:
    ■       setAttribute for parameter file.processingMode.
    ■       byDate for parameter file.processingOrder.
    Regards
    Patrick

  • A question about the Installation process in general

    Hey guys, a general question to the installation process.
    The following scenario:
    I install a programme on my macbook pro and don't tick all possible installation options (like additional content).
    Afterwards I change my mind and want to install the optional content.
    So I run the installation programme again and now the question:
    If I install the additional content AND the mainprogramme again is the main programme going to be overwritten or am I going to have the mainprogramme twice on my system from now on
    Thanks in advance for you help, folks!

    If you do a Unicode conversion (no matter in a UC & CU scenario or as a single project) the target system must be empty - means, you will create a new database and load it with the content you exported.
    You can't install the export into your already existing database with the same name.
    Markus

  • A question about Performance Settings

             Dear all.
                           Hi all,I want add a performance poller about Environmental Temperature.
                            There is an error as shown in the figur:
                            The device is Nexus 7010.  Is it support  this poller ?
                              If support,how to setting ?
                             Thank you very much

    Peanuts
     Thank you for your time and help.
    Dumb question  Reflash the firm ware
    Means Install the new firm ware list on this web site
    my old is v3.0.02 build 003 june 4, 2009
    The new one is v3.0.02 build 4 12/10/09
     The MTU thing  Ican figure out. click save OK. But what the heck  is
    Power cycle the router
    Un-plug it ?
    Sorry to  a pain.  Ready to throw this out the window.  It works good/great then very poor or not at all. In wireless mode.
     The other day on the lap top  a  friend was connected to a inter-active training video. for about 30 minutes, worked great.
     Then today the Dell with windows 7 lost the wireless conection.
    Thanks

  • Interview Question about performance

    Could somebody answer this.
    You get a call from database user complaining the database is very slow. Network issue is ruled out and you can't access any GUI tools like OEM, TOAD and Spot Light. What v$ views and columns would you see to if there is any issue with the db.
    thanks in advance.

    Questions like this one can go many directions. Since it is only one user complaining, I might start with v$session, v$process, and v$sql to get the sql text she is executing and test it for performance as a stand-alone query. I might also watch v$session_wait to see if I can see any sign of active waits for various sessions. Of course, if the user is doing a DML, then I might look at v$lock to see if any uncommitted transactions are blocking the user.
    That is just a start. There are many places to look and many possible causes of slowdown.
    Of course, the usual first questions is 'What has changed?'

  • A question about CPS (CPS processing) and CAPolicy.inf file.

    Hello All
    Can someone please help me with the following question.
    Background, I am building a 3-tier PKI infrastructure. offline Root, offline Policy (intermediate), online issuing.
    Now my first question is about CPS (certificate practice statement) for this example lets just call this the InternalIssuancePolicy as below.
    Basically I was thinking it is best not to set a given certificate (aka issuance) policy at the Root, the reason being I may wish to have different issuance policies at a latter date.
    For example right now I just want an issuance policy (CPS) for internal certificates only, therefore I am thinking set this at the Policy CA level, as below [InternalIssuancePolicy] (example OID) and then issuing CA certs from this Policy CA to the
    internal issuing CAs. If at a latter date I want a different policy (CPS) for issuance of external certificates I can build a new Policy CA under the existing Root with a different policy extension.
    Is the above logic sound?
    Questions:
    I am assuming from recent study that the CA cert issued to the Issuing CA will contain a single issuance policy "only" i.e. the one that was specified in the Policy CA 1.3.6.1.4.11111111.1.1.1.  If so I believe you cannot build a new
    issuing CA and submit the CSR to the Policy CA asking for a CA cert with any other certificate policy extension other than 1.3.6.1.4.11111111.1.1.1
    Is that correct?
    Also
    I saw a blog post which stated if are going to use certificate/issuance policies (other than all issuance policies) you should mark the extension as critical=true otherwise the policy just becomes glorified comment. I take the point but that leads me to
    two more questions
    1: How does the certificate changing engine or CryptoAPI enforce a certificate policy (as it is just a policy, e.g. written procedure). I am assuming all this means is it forces the client to process the extension and therefore check the certificate
    policy extension in the certificate does not violate the certificate chain but that is all it can do?
    2: If the certificate policy extension is set to critical and the URL referenced in the extension is not available (e.g. on a WEB Server and the client is working offline, but has a cached CRL), does setting the extension to critical also force the
    client to try and access the URL listed, or not (I am assuming not as you could just have a text block rather than URL).
    Any comments suggestions on my proposed three CAPolicy.inf files below for the 3-tier PKI (again offline Root and Policy)
    ** Root **
    [Version]
    Signature= "$Windows NT$"
    [Certsrv_Server]
    RenewalKeyLength=4096
    RenewalValidityPeriodUnits=Years
    RenewalValidityPeriod=20
    CRLPeriod=Years
    CRLPeriodUnits=1
    LoadDefaultTemplates=False
    AlternateSignatureAlgorithm=0
    [CRLDistributionPoint]
    [AuthorityInformationAccess]
    basicconstraintsextension]
    pathlength = 2
    critical=true
    PolicyStatementExtension]
    Policies = AllIssuancePolicy
    Critical = FALSE
    [AllIssuancePolicy]
    OID = 2.5.29.32.0
    ** Policy CA **
    [Version]
    Signature= "$Windows NT$"
    [Certsrv_Server]
    RenewalKeyLength=2048
    RenewalValidityPeriodUnits=Years
    RenewalValidityPeriod=10
    CRLPeriod=Years
    CRLPeriodUnits=1
    [PolicyStatementExtension]
    Policies = InternalIssuancePolicy
    Critical = False
    [InternalIssuancePolicy]
    OID = 1.3.6.1.4.11111111.1.1.1
    Notice = "Internal Certificate Policy"
    URL="http://pki.lab.local/Certenroll/CPS.txt"
    [AuthorityInformationAccess]
    URL=http://pki.lab.local/Certenroll/PolicyCA01.crt
    [CRLDistributionPoint]
    URL=http://pki.lab.local/Certenroll/PolicyCA01.crl
    [basicconstraintsextension]
    pathlength = 1
    critical=true
    ** Issuing CA **
    [Version]
    Signature= "$Windows NT$"
    [Certsrv_Server]
    RenewalKeyLength=2048
    RenewalValidityPeriodUnits=Years
    RenewalValidityPeriod=5
    CRLPeriod=Weeks
    CRLPeriodUnits=1
    CRLDeltaPeriod=Days
    CRLDeltaPeriodUnits=1
    LoadDefaultTemplates=False
    AlternateSignatureAlgorithm=0
    [AuthorityInformationAccess]
    URL=http://pki.lab.local/Certenroll/IssuingCA01.crt
    [CRLDistributionPoint]
    URL=http://pki.lab.local/Certenroll/IssuingCA01.crl
    [basicconstraintsextension]
    pathlength = 0
    critical=true
    Thanks All
    AAnotherUser__

    > Is the above logic sound?
    not that much. In this case 3-tier PKI could be reduced to 2-tier. Make default Offline Root CA and below it issuing CAs with desired policy OIDs. You will combine issuing CA with policy CA functionality. Additional tier will cost you a license, administration
    overhead and increased certificate chain processing delays. There is nothing wrong if you combine policy CAs with issuing.
    > I saw a blog post which stated if are going to use certificate/issuance policies (other than all issuance policies) you should mark the extension as critical=true
    where did you get this? Certificate policies should not be marked critical. Certificate chaining engine will take care of it, when application reqests CCE to validate desired policy.
    > does setting the extension to critical also force the client to try and access the URL listed
    no. Certificate chaining engine do not inspect policy qualifier URLs.
    > Any comments suggestions on my proposed three CAPolicy.inf files below for the 3-tier PKI (again offline Root and Policy)
    [CRLDistributionPoint]
    [AuthorityInformationAccess]
    [PolicyStatementExtension]
    Policies = AllIssuancePolicy
    Critical = FALSE
    [AllIssuancePolicy]
    OID = 2.5.29.32.0
    these sections are not required in root CA.
    [AuthorityInformationAccess]
    URL=http://pki.lab.local/Certenroll/PolicyCA01.crt
    [CRLDistributionPoint]
    URL=http://pki.lab.local/Certenroll/PolicyCA01.crl
    [basicconstraintsextension]
    pathlength = 1
    critical=true
    These sections are not required at policy CA. Afaik, CDP and AIA extensions are not supported in non-root CA configuration files. The same is with issuing CA. And your issuing CA is missing PolicyStatementExtension section.
    Vadims Podāns, aka PowerShell CryptoGuy
    My weblog: en-us.sysadmins.lv
    PowerShell PKI Module: pspki.codeplex.com
    PowerShell Cmdlet Help Editor pscmdlethelpeditor.codeplex.com
    Check out new: SSL Certificate Verifier
    Check out new:
    PowerShell File Checksum Integrity Verifier tool.

  • HCM Processes & Forms - Some questions about the PD Processes

    Hi Experts,
    At my Organisation we use HCM Processes and Forms and Organisation Management and MSS to manage Position Based Security (PBS).
    The MSS Managers have requested a form be developed which they can use to extend an existing Position to Employee temporary assignment (IT1001 S-P with A081 relationship) which is due to expire within the next 30 days. We recently upgraded to ECC EHP6 and I thought I would now have a go at developing this Form.
    While researching in SCN and SAP Press books on the ‘HCM Processes and Forms’ topic, I have discovered a lot of information that has assisted me so far in progressing this solution.
    There are a few givens that I have confirmed so far, which are as follows;
    Since we are using Positions (Organisation Management), the only option available here is to use the PD Process, which implies using the SAP_PD Back_End Service. Therefore this become the baseline to build upon.
    While researching in SCN and SAP Press books on this subject I could not find relevant information about what is possible using the SAP_PD Service to achieve my solution design for the above requirements and thus my post to the HCM P&F Community for assistance.
    My questions are as follows;
    In the solution design, I was considering to use the “Process without Start Object” or “Mass Start” to skip Step 1 - “Selection Object” and use a Generic Service to get all the positions for the Manager (along the lines of the SAP Standard Generic Service - find Positions in Manager’s area of Responsibility) and only retain the Positions where the End Date for the IT1001 A081 relationship in between the Effective Date and Effective Date plus 30 days. This should provide me with all the positions under the Manager that have the A081 relationship with the assigned employee that are about to expire within the next 30 days.
    I want the result presented on the Form in a Table format so that the Manager has to enter the Extension Start Date and End Date for the new assignment period.
    Is this possible using Standard Design Time functionality?
    2.       Or Instead of Question 1, could I use OADP to achieve the same result using a custom search class to return a list of multiple objects (Positions)which is used to populate the form?
    3.       I get the impression that the ‘Mass Start’ process is mainly for multiple employees. Can it also be used for multiple PD objects?
    4.       I get the impression that if I used the ‘Mass Start’ option I could only use this if I was CREATING a new object or assignment? (I take it that you cannot use the Mass Start option to CHANGE multiple existing objects. Only because I have not seen any SAP Standard examples of this yet!)   Please confirm if this is possible?
    5.       Has anyone used the “Query for Mass Start” option on a Process? How does that work? (Could I write a ‘SAP Query’ to get the positions I am interested in under the Manager?) Is there a sample SAP Standard process that uses a query?
    Your assistance would be greatly appreciated.
    Thanks in Advance.
    Regards,
    Steve

    no limit
    no limit
    limitations of what?
    you can use forms on mac, pc, and other systems

  • KDE4 + wallpaper slideshow: few questions about performance / tuning.

    Hello,
    I am using KDE 4.4 from pacman and set my desktop activity to slideshow. I would like to customize few things and thus - I have few questions:
    1) Is it possible to change / disable transition effect when changing wallpapers? All my desktop is choppy and not responsive while the wallpaper changes and I am wondering if there is a way to repair this? (all images used as walls are at max 3MB big, usually something about 1MB. I have 7200 RPM disk, 2GB of ram and rather fast graphics card with newest Nvidia drivers, so I don't know what is the cause of slowdown...)
    2) How can I programatically progress wallpaper to next image (not with the right click / Next Wallpaper image)?
    3) Is there a way to disable the wallpaper change while there is a fullscreen application running? I am asking this, because when I watch HD movies and the wall changes, movie playback is really choppy... (I think that answer to the first question will also help me in this case).
    I would be glad for any sugestions / interest in helping me;)
    Best regards,
    Mike.

    Hello
    1/ There's no way I know to remove the transition. Using the "raster" graphics engine helps a lot on performance : kill plasma-desktop and launch  `plasma-desktop -graphicssystem raster`
    2/ There's a plasma applet for this :
    http://kde-look.org/content/show.php/Ne … tent=94251
    http://aur.archlinux.org/packages.php?O … twallpaper
    Maybe you can adapt it to your needs / find out how it works.
    Last edited by xvello (2010-05-16 16:20:24)

  • A simple question about the Integration process and the PI system

    Hi all
    Out PI system gets more and more slowly .
    in the Monitor I can se that there are many ufinished IP about 100.
    in the Outbound colon there is a Watch icon with the message
    QMessage being sent                     
    and in the graphic of the IP thers is a Send Message Asynchronously  with text in process.
    my question is can those unfineshed IP be guilty in slowing down the system by taking resources, they have been there for quit a long time .
    Thanks

    Hi again
    I have checked sm12 , no locks
    theres is no mapping involved in this step , the IP is trying to send a file to  server.
    I just want to know if  100 unfinished IP slow down the system .
    It does not matter if the file has been sent or not
    is there any way to check those IP if they are taking resources.
    Thanks.

  • LOB question about performance, fragmentation etc.

    Well..
    I want to discuss the issues around LOB objects.
    If I have an enttity class with n-count fields and then a lob as the n+1th field, does this affect performance in any way ? E.g. if performance is random access for an object without a lob, does the performance get linear or something when the lob is introduced?
    Another one:
    If the latter is true: is it an option for me to use an @OneToOne mapping to compensate ?
    What about fragmentation ? How can a database or whoever compensate for fragmentation, in the case the lob is the n+1th field ? Or just in general: How the fragmentation issues are handled?
    (Im just thinking that lobs introduce fragmentation and brings performance down...)

    This will be san=me if you are considering the Local interfaces.
    For remote interface(like accessing EJB from Servlets resides in diffferent Apps Server) use the DTO(data Transfer Object) patterns.
    Regards
    Sushil

  • Question about performance (entities & data object)

    Hello:
    I know that this can be, maybe, a silly question, but I've got the doubt
    I get a local reference to a entity ( myEntityLocal ) and I'm going to get many values from it.
    For example
    myEntityLocal.getId();
    myEntityLocal getName();
    myEntityLocal.getAddr();
    etc etc
    My question is
    Would be better, in performance terms, to fill all fields into a data object myEntityData ) and retrieve them from it ?
    I mean
    myEntityData = myEntityLocal.getData() // where getData() calls getter methods on myEntityLocal
    myEntityData.getId();
    myEntityData.getName();
    myEntityData.getAddr();
    I think the result is the same because is a local reference, but I've got that doubt
    Thanks and regards

    This will be san=me if you are considering the Local interfaces.
    For remote interface(like accessing EJB from Servlets resides in diffferent Apps Server) use the DTO(data Transfer Object) patterns.
    Regards
    Sushil

Maybe you are looking for