Thread creation questions

I'm creating a diary type program (dates and times of various things) and am having a few problems creating threads. I'm understanding how to create the threads I think, but from what I've been able to understand, everything that the tread runs is in the run() method only. So how do I make it run other things?
for instance, I have a search method which searches through a load of objects (the tasks). Can I run this search method in its own thread?
Thanks
Adrian

agehoops wrote:
Well I plan to put a GUI on the top of it so obviously that'll have its own thread but I don't want anything to lock up while it's searching through potentially hundreds of objectsThat's a little better. If you are using Swing and Java 6, have a look at using a SwingWorker object. It smooths over some of the difficulties of doing Threading with Swing. There's a decent tutorial on using this here:
[Lesson: Concurrency in Swing|http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html]

Similar Messages

  • I don't understand the thing you call live bookmarks never used it, and most forums I have used notify VIA E-mail not giving out my E-mail address information when a reply has been made to the thread in question.

    So how do I get notified of updates in this forum? As I said: I don't understand the thing you call LIVE BOOKMARKS I have never used them, and most forums I have used notify VIA E-mail not giving out my E-mail address, or other private information when a reply has been made to the thread in question, so how do I get notified of updates in this forum? I have seen no normal options for setting my viewing preferences used for this forum. Thank You.

    Thanks for your reply via email/msg. He wrote:
    If you are interested in the actual design data for the Xeon processor, go to the Intel site and the actual CPU part numbers are:
    Xeon 4 core - E5.1620v2
    Xeon 6 core - E5.1650v2
    Xeon 8 core - E5.1680v2
    Xeon 12 core - E5.2697v2
    I read that the CPU is easy to swap out but am sure something goes wrong at a certain point - even if solderedon they make material to absorb the solder, making your work area VERY clean.
    My Question now is this, get an 8 core, then replace with 2 3.7 QUAD CHIPS, what would happen?
    I also noticed that the 8 core Mac Pro is 3.0 when in fact they do have a 3.4 8 core chip, so 2 =16? Or if correct, wouldn't you be able to replace a QUAD CHIP WITH THAT?  I;M SURE THEY ARE UO TO SOMETHING AS 1) WE HAVE SEEN NO AUDIO FPU OR PERHAPS I SHOULD CHECK OUT PC MAKERS WINDOWS machines for Sisoft Sandra "B-E-N-C-H-M-A-R-K-S" -
    SOMETHINGS UP AND AM SURE WE'LL ALL BE PLEASED, AS the mac pro      was announced Last year, barely made the December mark, then pushed to January, then February and now April.
    Would rather wait and have it done correct than released to early only to have it benchmarked in audio and found to be slower in a few areas- - - the logical part of my brain is wondering what else I would have to swap out as I am sure it would run, and fine for a while, then, poof....
    PEACE===AM SURE APPLE WILL BLOW US AWAY - they have to figure out how to increase the power for 150 watts or make the GPU work which in regard to FPU, I thought was NVIDIA?

  • Regarding Thread Creation

    Hello,
    To create a thread in java there are two methods.
    (1) by extending from thread class.
    (2) by implementing runnable interface.
    implementing runnable interface is the preferred method to create a thread because we still have the option to extend from any other class.
    But does anybody know why java provides 2 methods for thread creation, why doesn't it provide only option 2 (i.e. by implementing runnable interface) when it is the preferred option.
    Regards,
    Sandy.

    Though Runnable interface is preferred to create threads in Java,most programmers extends Thread class.As jschell would say, 'I am rather certain' that the opposite is true.
    The reason behind of this is that you can have a clear logic of your code by using ThreadThat's not even true and it certainly isn't a reason to extend Thread rather than implement Runnable.
    most of the system programming written in java used Thread class instead of Runnable interface .If you have some evidence on the point please produce it. The consensus of opinion on these forums has been the other way round for many years.

  • Thread creation error: Not enough storage is available to process this command

    Two user in my company have this problem, I have already used the solution on the community but would come back after 2 to 3 weeks. They all have the message "Thread creation error: Not enough storage is available to process this command". I tried increase the virtual memory to 4Gb, update one client to the latest, reset IRPStackSize, delete temp folder.  one client is 7.5.XX with windows 7 and another is 6.20.0.104 with Windows XP,My machine is also 6.20 with windows 7 but I dont have this problem.   

    Version previous to 7.6 worked fine. After update I have got this message and mostly of Skype GUI turns black or vanishes. No possibility of making more than one call before crash, It is amazing that a thread started about two weeks ago has no technical answer, at least. What do I do with my credits and my appointments? Throw them away?

  • Thread creation error: Not enough storage space

    Hi,
      Recently (the past week or so), my desktop client for Skype has been crashing regularly. This is accompanied by large (over 1.2GB) amounts of memory usage. At semi-regular intervals (say every few hours), Skype will post an error with the text "Thread creation error: Not enough storage space..."
    I am using the latest build of Skype. I am not performing any Skype logging. This error is clearly an ongoing issue which has not been addressed, as prior threads have discussed this as well.

    Errors like this have been addressed and continue to be addressed.  Being that the errors are related to memory leakage of one form or the other, the problem can have several sources and be agitated by several programs.  I personally run the latest version on all my machines in a 24/7 capacity and have not run into the problem.  Some versions in the past created a similar error for me, yet the latest has not.  If you've already updated your IE's flash and that has not alleviated the problem, the only other solution is running an earlier release that doesn't crash for you or restart Skype more often.  I've had virtual video devices trigger this behavior by simply launching the video settings once.  The virtual device even when not in use continued to consume memory under Skype until it crashed.  So if you use any virtual audio/video components you may want to remove them to see if that changes anything.  Some people have also blocked ads when those were the source.
    http://community.skype.com/t5/Windows-desktop-clie​nt/low-storage/m-p/3974193/highlight/true#M344826

  • RoboCode crashes with SeedGenerator thread creation error?

    Hello everyone.
    I recently came across a game called RoboCode. It seems to be a tank battle simulator where you write the AI in Java.
    Unfortunately, it won't start on my Windows computers. I get this error:
    Exception in thread "SeedGenerator Thread" java.lang.InternalError: internal error: SeedGenerator thread creation error.
            at sun.security.provider.SeedGenerator$ThreadedSeedGenerator.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)Anyone got any idea why? I haven't the foggiest clue how to fix it or get around it - or even what it means.
    Thanks,
    -Kramy

    I'm awaiting a reply right now.
    But if Google couldn't turn up much, then it probably isn't a very common error? ;)

  • Callbacks without excessive thread creation and memory leaks?

    Hi JNI experts,
    I haven't done any serious JNI programming in a couple years and I'm currently stuck with a tricky JNI problem:
    My JNI code is connected to a system driver and needs to do frequent callbacks into Java code. The standard way of doing this involves calling AttachCurrentThread and DetachCurrentThread before/after the callback to Java code. However, I noticed that AttachCurrentThread creates a new java.lang.Thread each time it is invoked. Let's just say that the callback is invoked from JNI very freqently, and creating a new Thread each time that happens is not acceptable behavior for my application. Among other things, it prevents me from using the Eclipse debugger because the large number of threads being created and destroyed effectively locks up Eclipse's debugger UI. Also, it creates a CPU load that is way higher than it should be for a light-weight operation.
    So, I deviated from the standard Attach/DetachCurrentThread pattern and moved the DetachCurrentThread to code that is only called when the native JNI service is terminated. As that effectively renders repeated AttachCurrentThread calls a no-op, the problem of excessive creation and destruction of threads went away, but instead I had a memory leak on my hands now. The JNI code needs to create some Java objects because it's easier to create those objects right away rather than passing a bunch of primitives to Java and assembling them into objects there. When I moved the DetachCurrentThread, those newly created objects were no longer garbage-collected even after the Java code had released all references.
    When you print the stack trace of the Java callback method there is always only one frame on the stack (since it is being invoked directly from JNI). However, I suspect that older stack frames from previous invocations keep hanging around somewhere else in memory if DetachCurrentThread is not called. In other words, moving DetachCurrentThread out of the callback is an even worse option. I tried using PopLocalFrame to get rid of left over stack frames, but that didn't seem to work.
    So, my question is: is there a way to make (natively initiated) callbacks from JNI to Java without memory leaks and without creating a new thread each time? Would it work if I created my own native thread that runs some sort of dispatch loop? What other options are there?
    Thanks for any ideas!

    Thanks for the quick reply, ejp! :-)
    Your comments were very helpful; let me clarify a few things:
    I don't know where you get this 'standard Attach/DetachCurrentThread pattern', but if the native callbacks always happen on the same native thread, you only need to attach it once when you get the first callback, and detach it when you get the last, if you can tell. ;-)Yes, the callback is always coming from the same native thread, but, unfortunately, I cannot tell when I get the last callback, and essentially the native service keeps running as long as the VM is running. When I say "standard pattern" I'm referring to the fact that pretty much every book, tutorial, or web site that talks about JNI callbacks shows code snippets where AttachCurrentThread is called, then the callback, and then DetachCurrentThread.
    The JNI code needs to create some Java objects because it's easier to create those objects right away rather than passing a bunch of primitives to Java and assembling them into objects there.Is it really? Are you sure?I'm pretty sure in this case, though your point is well taken. The native API that calls my JNI code produces packets of that contain about 15 pieces of information of different types (ints, longs, doubles). Several packets may arrive together in a single group. Handling the data on the Java side requires a Java callback method with 15 parameters for a single packet, and it's hard to reconstruct which packets belong to one group at that point. Creating corresponding Java objects in JNI and passing them inside an array to the callback function indeed turned out to be easier.
    I don't think just 'moving' the DetachCurrentThread is correct. You need to attach the thread that is doing the callbacks, as often as necessary but no oftener, and detach it when you can.I think I found the solution: my native code is starting a separate dispatcher thread that, as you suggested, attaches itself only once and then enters a dispatcher loop. The low-level call back function notifies that thread of new data via the standard Pthread API. The detach happens in JNI_OnUnload. This works without creating a new thread each time and garbage-collects the created objects properly. As the dispatcher method essentially never returns I also had to insert some DeleteLocalRef calls, because otherwise the local references prevented garbage collection.
    So, for now, it looks like I'm good to go. Thanks again for the reply!

  • WD Java iView Creation Question/Issue - CE 7.1 EHP 1 Trial

    Hi all,
    Im posting this question here seeing as that the issue has arrised on an installation of the AS JAVA and EP shipped with CE 7.1 EHP1 Trial.
    When attempting to create an iView for a deployed custom WD Java app on the trial Portal I am taken straight to the iView template selection without being given the options for iView creation( ie. create from template, portal component or WD Java app). Is this by design ( WD Java iView creation has changed from previous Portal versions or is limited in Trial installation), is this an issue with the components shipped with the Trial or an issue on my installation only?
    Currently my only solution for deploying WD java content is to copy the actual application and paste it as Portal content which then creates a WD Proxy page with a single WD Proxy iView (that of the copy pasted WD app). This is fine for single app scenarios but becomes an issue with multiple apps on one page and drag and relate scenarios.
    Kind regards,
    Willem.

    Hi Williem
    Please check the SAP CE 7.1 EHP1 documentation for more information.
    [CE 7.1 documentation|http://help.sap.com/saphelp_nwce711/helpdata/en/44/d958673ef05f4de10000000a11466f/frameset.htm]
    [CE 7.1 iViews  |http://help.sap.com/saphelp_nwce711/helpdata/en/f5/eb51590e6a11d7b84900047582c9f7/frameset.htm]
    Hope this will helps you.
    Thanks
    Arun Jaiswal

  • Static method,new thread performance question

    Hey guys i just have two questions about two methods used in many controllers/servlets in my app:
    1-what is the difference between calling a static method in a util class or a non static method (like methods dealing with dates i.e getting current time,converting between timezones), which is better ? 2-what is the difference between calling a method(contain too many logic like sending emails) in the controller directly or running this method in a different thread ?

    cs.student wrote:
    Hey guys i just have two questions about two methods used in many controllers/servlets in my app:
    1-what is the difference between calling a static method in a util class or a non static method (like methods dealing with dates i.e getting current time,converting between timezones), which is better ?Depends on the design. It's impossible to say straight why one way would be better than another. Programming isn't that straight forward.
    2-what is the difference between calling a method(contain too many logic like sending emails) in the controller directly or running this method in a different thread ?Threads can be run at the same time. So what you're asking is "what's the difference between doing one thing after another and doing two things at the same time".

  • High Level Thread Implementation Questions

    Hi,
    Before I take the plunge and program my software using threads, I have a few high-level questions.
    I plan on having a simulation class that intantiates software agents, each with different parameters. There is an agent class, with constructor, methods etc. Each agent has a sequence to go through. Once completed, the iteration number is increased and the sequence is repeated. That's simple enough to do.
    The question is, is it worth executing each agent on a different thread?
    If there is around 500 - 1000 lines of code (crude measurement, I know) how many can I expect to thread efficiently?
    One parameter allows an agent to execute n cycles for each global iteration. (i.e. in one iteration, agent A runs once, agent B runs 5 times). Could this be a problem? Should this be controlled outside the agent, or inside it?
    Can I write the code without having to worry about threading, or do I have to design the agent code with threading in mind?
    Will they really run in parallel? It is important that there is no bias to the execution order. I can solve this messily without using threads by randomising the execution order - but that is a messy work around - and why I'm looking at threads.
    Can threaded objects interact easily with non threaded one when execution order is important?
    Are there any other points that I should consider?
    Thanks in advance - any information before I enter this unchartered territory will be truly appreciated!!

    I think you are better off running this all in a single thread.
    Threads make no guarantee as to scheduling. Threads do not increase efficiency (unless your agents block on i/o, or sleep). Threads come with an overhead cost.
    Threads don't guarantee no bias to execution order.
    Threads require synchronization to ensure safe interaction between each other. This is a bit of extra work, and can be a bitch if you're not familiar with it.
    Yes, threads run in parallel. If you have multiple processors then they can truly run in parallel, otherwise they run in time slices.

  • "Pause" Thread, thread creation & run performance

    Hello,
    I'm having an object executing tasks in response to events (I call it Executer)
    In "normal" execution mode, it's executing 2 types of tasks: tasks1 and tasks2.
    when a specific event occurs (pauseEvent), I want it to STOP executing tasks2 for a specific amount of time (in this example 100ms): I'm calling that a "pause"
    it will still be executing tasks1 in the meantime, and will resume executing tasks2 only after the pause has expired.
    to do so, when I receive a pauseEvent I create a new Thread (PauseThread) and start it.
    it itself calls the "setPause(boolean p)" method of Executer to set the "pause" flag to true
    then it waits for 100ms
    then it sets back the pause flag to false
    (Executer checks the pause flags before executing tasks2)
    class PauseThread extends Thread {
        private TaskExecuter  executer;
        private long                pauseTime;
        public PauseThread(Executer e, int t) {
            executer = e;
            pauseTime = t;
        public void run() {
            executer.setPause(true);
         try {
                sleep(pausetime);
            catch(InterruptedException e) {
                System.out.println("exception pause thread");
         executer.setPause(false);                
    }all is working fine.
    however, I'm trying to improve performances.
    the whole process of creating & starting the thread takes up to 50us, I want to reduce this as much as possible.
    obviously, I create & start a thread every time I want to do a pause, I'm thinking there MUST be a way to avoid this, and simply call the setTrue / Sleep / setFalse part of the thread instead.
    I was thinking about creating and starting the thread only once at the creation of my Executer, and calling the "pause()" method when needed:
    class PauseThread extends Thread {
        private TaskExecuter  executer;
        private long                pauseTime;
        public PauseThread(Executer e, int t) {
            executer = e;
            pauseTime = t;
        public void run() {
         while(true) {
        public void pause() {
            executer.setPause(true);
         try {
                sleep(pausetime);
            catch(InterruptedException e) {
                System.out.println("exception pause thread");
         executer.setPause(false);                
    }would that be correct ?
    I'm concerned with the performance hit of the "while(true)" (as I'm fighting for micro-seconds, even the slighliest useless cpu hit should be avoided)
    what if I had "sleep(1)" in my while loop ?
    I'm pretty sure there's a better way to do this, any idea ? maybe using wait / notify, however I get the feeling those methods are not designed for this use...
    any hint ?
    thanks !

    yes, I'm certainly reinventing the wheel ! but trying to understand it at the same time !
    what was your other suggestion ? Timer + TimerTask ? I've already implemented it and using it now ! as I said it's working good, 3x improvement ! simply trying to see if there's a way to avoid creating a TimerTask object at each run.
    coming back at the "piece of nonsense", what would this achieve:
    class PauseThread extends Thread {
        private TaskExecuter  executer;
        private long                pauseTime;
        private boolean           flag = false;
        public PauseThread(Executer e, int t) {
            executer = e;
            pauseTime = t;
        public void run() {
         while(true) {
                if(flag) {
                    flag = false;
                    sleep(pauseTime); // add try/catch
                    executer.setPause(false);
        public void startPause() {
            flag = true
    }then in my Executer, I create and start the PauseThread only once, and when I want to pause it, I simply do:
    setPause(true);
    pauseThread.startPause();in this case the sleep would execute in the run(), pause the "pause" thread, not the "executer" thread, no ?
    I will read about the concurrency classes...

  • Dynamic Thread Creation

    To anyone that can help,
    I am very new to JAVA, and have been given the job of creating an application that allows a user to dynamically create a number of process which perform the same task (its a load-testing tool). I thought that using threads would be the best approach, however, I am not sure how to instantiate them dynamically. The two ways I known are :
    1.
    NewThread one = new NewThread(arguements);
    one.start();
    2. new NewThread(arguements).start();
    The second one would probably work via. user input. The problem is that since I haven't named the object (like in case 1) I can't access its methods (i.e. join()). I guess this question could be extend to consider creating any object dynamically, so any help would be very much appreciated.
    Thanks

    I'm not entirely sure of what your question is... but I'll try to guess at it.
    The only difference between the two approaches is whether your program will keep a handle/reference to the class that extends Thread or implements runnable.
    NewThread one = new NewThread(arguements);
    one.start(); In the first case you can just take your "one" variable and throw it into a container, if you want to reference it and others like it.
    2. new NewThread(arguements).start(); In this case, you don't have a variable that references the thread that you just started.
    Can you provide more information on what you want to do with the Thread process once it has started?
    Thanks,
    Tim
    To anyone that can help,
    I am very new to JAVA, and have been
    and have been given the job of creating an application
    that allows a user to dynamically create a number of
    process which perform the same task (its a
    load-testing tool). I thought that using threads would
    be the best approach, however, I am not sure how to
    instantiate them dynamically. The two ways I known are
    1.
    NewThread one = new NewThread(arguements);
    one.start();
    2. new NewThread(arguements).start();
    The second one would probably work via. user input.
    The problem is that since I haven't named the object
    (like in case 1) I can't access its methods (i.e.
    join()). I guess this question could be extend to
    consider creating any object dynamically, so any help
    would be very much appreciated.
    Thanks

  • Thread creation in c++

    Hi, all !
    I am working on a c++ program. I have created a class called threads abnd now I want to know whether there is a function for creating threads.I am new to solaris.I don't have a idea about what function to use to create threads in c++.
    I also want to know whether there is a function to synchronize the created threads while they are accessing a shared memory. Thankyou very much.
    Vij.

    Please do not post the same question more than once. See my answer here:
    http://forum.java.sun.com/thread.jspa?threadID=5128430

  • JDeveloper Webservice Creation Question

    While Creating webservices through JDev 11g from WSDL, we are presented with two option :-
    1) Java EE 1.5, with support for JAX-WS annotations
    2) Java EE 1.5, with support for JAX-WS RI
    Could you please let me know which one is the most efficient option.
    I see that in the second option the webservices are configured thru another file(sun-jaxws.xml) and all the requests are directed or handled by a common servlet whereas in the first option we usually configure the endpoint implementation directly in web.xml.
    Another question that i have related to webservices creation - Does webservices wizard internally call wsimport to generate classes from WSDL. When i use wsimport to generate classes using WSDL and specify a jaxb global binding file to convert datatypes, this works correctly but using JDeveloper doesn't creates the Adapter classes to convert the datatypes.
    Answers to the above would be helpful in reaching a decision on which approach to follow. Thanks.

    Hi,
    yes. Please see the how-to document we provide on otn.oracle.com/products/jdev
    Frank

  • Thread.MemoryBarrier() questions

    Hi!
    I'm trying to avoid my code being rearranged by the CLR using Thread.MemoryBarrier(), as such:
    /// <summary>
    /// Client created a character!
    /// </summary>
    public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P)
    Logger.LogInfo("Received CharacterCreate!");
    string AccountName = SanitizeAccount(P.ReadPascalString());
    //Need to be variable length, because the success packet contains a token.
    PacketStream CCStatusPacket = new PacketStream((byte)PacketType.CHARACTER_CREATION_STATUS, 0);
    using (var db = DataAccess.Get())
    Account Acc = db.Accounts.GetByUsername(AccountName);
    if (Acc.NumCharacters >= 3)
    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit);
    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
    return;
    //TODO: Send GUID to client...
    Sim Char = new Sim(Guid.NewGuid());
    Char.Timestamp = P.ReadPascalString();
    Char.Name = P.ReadPascalString();
    Char.Sex = P.ReadPascalString();
    Char.Description = P.ReadPascalString();
    Char.HeadOutfitID = P.ReadUInt64();
    Char.BodyOutfitID = P.ReadUInt64();
    Char.Appearance = (AppearanceType)P.ReadByte();
    Char.ResidingCity = new CityInfo(false);
    Char.ResidingCity.Name = P.ReadPascalString();
    Char.ResidingCity.Thumbnail = P.ReadUInt64();
    Char.ResidingCity.UUID = P.ReadPascalString();
    Char.ResidingCity.Map = P.ReadUInt64();
    Char.ResidingCity.IP = P.ReadPascalString();
    Char.ResidingCity.Port = P.ReadInt32();
    Char.CreatedThisSession = true;
    var characterModel = new Character();
    characterModel.Name = Char.Name;
    characterModel.Sex = Char.Sex;
    characterModel.Description = Char.Description;
    characterModel.LastCached = ProtoHelpers.ParseDateTime(Char.Timestamp);
    characterModel.GUID = Char.GUID;
    characterModel.HeadOutfitID = (long)Char.HeadOutfitID;
    characterModel.BodyOutfitID = (long)Char.BodyOutfitID;
    characterModel.AccountID = Acc.AccountID;
    characterModel.AppearanceType = (int)Char.Appearance;
    characterModel.City = Char.ResidingCity.UUID;
    characterModel.CityName = Char.ResidingCity.Name;
    characterModel.CityThumb = (long)Char.ResidingCity.Thumbnail;
    characterModel.CityMap = (long)Char.ResidingCity.Map;
    characterModel.CityIp = Char.ResidingCity.IP;
    characterModel.CityPort = Char.ResidingCity.Port;
    var status = db.Characters.CreateCharacter(characterModel);
    switch (status)
    case LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted:
    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted);
    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
    break;
    case LoginDataModel.Entities.CharacterCreationStatus.NameTooLong:
    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameTooLong);
    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
    break;
    case LoginDataModel.Entities.CharacterCreationStatus.Success:
    Guid Token = Guid.NewGuid();
    //This actually updates the record, not sure how.
    Acc.NumCharacters++;
    Thread.MemoryBarrier();
    //THIS NEEDS TO HAPPEN FIRST FOR CITY SERVER AUTHENTICATION TO WORK!
    foreach (CityInfo CServer in NetworkFacade.CServerListener.CityServers)
    if (CServer.UUID.Equals(Char.ResidingCity.UUID, StringComparison.CurrentCultureIgnoreCase))
    PacketStream CServerPacket = new PacketStream(0x01, 0);
    CServerPacket.WriteHeader();
    ushort PacketLength = (ushort)(PacketHeaders.UNENCRYPTED + 4 + (Client.RemoteIP.Length + 1)
    + (Char.GUID.ToString().Length + 1) + (Token.ToString().Length + 1));
    CServerPacket.WriteUInt16(PacketLength);
    CServerPacket.WriteInt32(Acc.AccountID);
    CServerPacket.WritePascalString(Client.RemoteIP);
    CServerPacket.WritePascalString(Char.GUID.ToString());
    CServerPacket.WritePascalString(Token.ToString());
    CServer.Client.Send(CServerPacket.ToArray());
    break;
    Thread.MemoryBarrier();
    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.Success);
    CCStatusPacket.WritePascalString(Char.GUID.ToString());
    CCStatusPacket.WritePascalString(Token.ToString());
    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
    break;
    Will it work on sections of code, or simply on the next statement following it? Is there any other ways to make sure my code is run in the order I specified? 

    >>Will it work on sections of code.
    Yes, Thread.MemoryBarrier() works like a fence that makes sure that the processor that executes the current thread cannot reorder instructions in such a way that any
    memory access before the call to the Thread.MemoryBarrier() method is being done after the call to the method.
    The lock statement implicitly generates a full memory barrier, i.e. lock (_lock) { ... } is equivalent to Thread.MemoryBarrier(); { ... } Thread.MemoryBarrier(); as far as memory barriers are concerned.
    You only need memory barriers when working with shared writable fields though. Please refer to the following page for more information:
    http://www.albahari.com/threading/part4.aspx.
    Please also remember to mark helpful posts as answer and/or helpful and please start a new thread if you have a new question.

Maybe you are looking for

  • Status de erro: 50 - Cancelamento/inutilização: erro de sistema PI

    Boa noite, srs! Estamos com um problema na inutilização e cancelamento de NFe junto ao SEFAZ. Foi executado o report J_1BNFECHECKNUMBERRANGES para inutilização de numeração de NFe. A tabela J_1BNFENUMGAP foi preenchida com a numeração, porém a mesma

  • Java Printing API - Unable to print on HP LaserJet

    Hi, I'm trying to use Java's printing API to print a PDF file onto a network/local printer. My code works fine when I try printing onto Canon printers but the behavior is erratic on HP LaserJet printers. I've tried using two different models of HP La

  • Why are there no login bars on Amazon and other sites on my computer?

    When i go to log in on Amazon or even just go to Kroger.com and try to complete a survey, the spaces/bars do not appear for me to enter my information into. I have tried nearly everything i can find including starting firefox in safe mode so it can't

  • Replacing a certaing string

    I need help with a program. Im talking about a Java application, not an internet based Java applet. Here are the steps: 1)User inputs a string 2)User inputs the word the user wants to change 3)User inputs the word the user wants the word in #2 to be

  • Approval in SD

    dear all, can any one provide the details of approval process or release process of sales orderds like IN,QT,order . regards barani