Java threads. Are they running at the same time?

Hello everybody. I am implementing a multiagent system in java and at some point in the program i need a specific function (from a specific class) to run at the same time in several "copies". Those functions are communicating with each other with some messages, so as you can understand not running at the same time is a big problem because of this messages.
Below i am giving you an example of the code i am using. I would like your opinion whether those functions are running parallel or serial. If they are not running parallel what should i do? Any opinion or something that can help me would be perfect. Thanks in advance.
//my class
public class Agent extends Thread {
                       public void MinConflicts(Agent array[],int max_moves){//code in here}
public static void main(String[] args) throws IOException {
              Agent[] fbi = new Agent[num] //num is inserted by the user
             //code here
             for(i=0;i<num;i++){
                     fbi.start(); //starting the treads
for(i=0;i<num;i++){
fbi[i].MinConflicts(fbi,max_moves); //running the function that i want to run parallel
//code here also :)

What you appear to be doing here is creating an array of Thread references (which I hope at some point gets populated with actual Thread object references!)......because your first loop is wanting to cycle through each array slot starting the referenced Thread. Then the next loop iterates through the array again, this time calling the method for each Thread object.
Assuming that you do populate the array, what this code will do is start each Thread which, I believe, will start and immediately terminate because run() has not been over-ridden. The second loop winds up calling the method for each Thread in the array. You are actually calling it from the main thread though. So, as previously advised, I think that you will run each method sequentially.
The direction that I would head with this is to override run() in your agent Thread and have that run() method call the MiniConflicts() method. Then, in your main routine you can do away with the second for loop. The looping start will start all of the individual threads and they will execute the run() method......which in essence will be executing your MiniConflicts method.
This reply is NOT a total design... I am sure that there are holes to be filled... but I think that will get you headed in the right direction.

Similar Messages

  • How many threads can be running at the same time

    Hi!!
    Dows anyone knows how many Threads can be running at the same time in the JVM.
    I'm making a multi thread client-server app and I would like to know how much simultneous connections the JVM support. I'm using one Thread per connection.

    Hi, thanks to all for your answers.
    I think that I made the wrong question, as you said: "that means the number of threads currently created".
    I'm worry about this because my application is already online (It's a mail server -SMTP and POP3 server using ORACLE for the users database- ) and some other user post in the "multi-tread forum" that almost any JVM can only have 700 threads created at the same time, and I've never heard or read anything about this.
    what you mean with the stack space (memory??)
    I'm using the JavaWebServer 2.0 and a servlet to start the main Thread.
    Again Thanks to all for the answers but I think that the schapel answer is the one that solve my doubt...

  • Two Telnet read VI's running at the same time interfere with each other

    I have a situation where multiple tests must test multiple UUT’s on the same computer. To send commands to and get responses from the UUT's I use a telnet session. The telnet read VI uses a semaphore. Therefore when two separate top level VI's are running, each calling the Telnet read VI, if one Top Level VI is using the Telnet Read VI the other Top Level VI waits for the first one to complete before it can use the Telnet Read VI. This VI is setup for reentrant execution but because of the semaphore it cannot truly be used as a reentrant function. This causes severe problems when trying to communicate with two different telnet sessions simultaneously.
    In the past I have avoided this problem by compiling everything into an executable. Then each Top Level program runs completely independently with no interdependences. However, now I am implementing Teststand and I need to call the same Top Level VI's. I need to be able to get information into them and back out of them from Teststand. This means that I can no longer compile them into stand alone executables. I did compile each top level VI into its own Share DLL thinking that then each top level program would have its own library to call upon. This did not work. Even though both top level programs are compiled into their own DLL there is still interdependency when calling the telnet read VI. One program waits for the other to finish reading from its telnet connection before it can read from its own telnet connection. Since I have to continuously read from the telnet connection, sometimes for up to half and hour, the tests do not function simultaneously. How can I get around this? Is there a solution?
    Josh
    PS The Telnet Read VI I am refering to came with the Internet Toolset package. Attached is a copy of the VI I use to communicat with the UUT's.
    Attachments:
    GUI_Telnet_W-R_Auto.vi ‏64 KB

    Sorry about the confusion.
    The file I attached is in the hierarchy of two separate top-level VI's. The telnet connect is opened once and closed once in each top-level program. The ref number is then passed into and out of the VI that I attached. I use this VI to repeatedly send commands via telnet and wait for the appropriate responses. The telnet read VI is given a read line separator and reads from the telnet connection until it matches the read line separator with a text string read back from the telnet connection. If not match is found it times out and creates an error.
    I am not sure how to provide an example of the overall scheme since the problem occurs when both top level VI's are compiled each into their own shared DLLs. Those DLLs are then call from Teststand and at some points they are both running at the same time on the same computer connected to two different UUT's.
    The question I have is why does one DLL share functions with the other? When one DLL is using the telnet read VI the other DLL waits for the first one to finish with it before it can it use the telnet read VI. If they were both compiled separately each into their own DLL shouldn't they each have their own set of functions to call upon instead of having to share? I know that if the two top-level VI's are not compiled they cannot both execute the same sub-VI at the same time. The only way to get around this is to set the execution property on the sub-VI to reentrant.
    I actually fixed the problem by setting the VI I attached and the Telnet Buffered Read.VI (called by Telnet Read.vi) execution properties to reentrant. However, I am still concerned about two separate DLLs sharing sub-VIs. Why does it do this?
    Joshua

  • Do queries in the datamodel run at the same time or 1 at a time?

    I am using Oracle Reports Developer 10g and I wanted to know when the
    the queries are fired from the data model. If there are more than 1 do
    they run 1 at a time or do they run at the same time.
    Howard

    My purpose for asking this question is to speed up the report. After running a trace. I see there are 6 program units that return values base on the input prior to getting the counts and generating the page layout. My question is could I speed this up
    by removing the plsql and replacing it in the sql with a decode?
    Howard
    Edited by: hh**** on Oct 4, 2012 3:07 PM

  • HT201335 My iphone (ios 7.1) is not showing the apple tv icon from my pull up center control? They are both running on the same wifi network... Any ideas on how to fix this problem?

    My iphone (ios 7.1) is not showing the apple tv icon from my pull up control center? They are both running on the same wifi network... Any ideas on how to fix this problem?

    Was it working before? Is your Apple TV enabled for airplay?
    See
    http://support.apple.com/kb/TS4215?viewlocale=en_US&locale=en_US

  • Is it possible to have 2 threads running at the same time?

    Is it possible to have 2 threads running at the same time at different times eg 1 repeats every 20 miliseconds and the other 40 for example. Also could you have 2 run() methods in one script, in one file? If so how? Help soon would be appreciated. Thanks.

    Is it possible to have 2 threads running at the same
    time at different times eg 1 repeats every 20
    miliseconds and the other 40 for example. Yes.
    http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html

  • Having two background brarchive running at the same time with -f 1 options

    Good morning,
    I need to run two brarchive in parallel as background  process.
    I would like to have on for the save and one for the copy.
    I need that because they would have different files.
    1. Is this configuration supported or not?
    As a file is created for the locking (.lock.bra) I have the feeling that a single process is supported?
    2. Just to double check, can I run two brarchive with two different config file in a serial manner
    (lauch the 1st one, wait for its end, launch the 2nd one, waits for its end).
    3. If you are using that kind script on your systems, could you please provide them?
    4. If brarchive is launched by a script how do you shut it?
    Do you do just a kill of the script or do you kill it and send another signal to the brarchive if it is currently running?
    Thanks in advance for your answers.

    Good afternoon Eric,
    > Why do you want to use option -f 1? what are the reasons being this?
    -f makes it run in background.
    For me, there two advantages for doing that.
    1. You start it once, when you start sap, and it runs regularly
    2. When you stop sap, you stop braarchive.  Then you are sure that no crontab jobs are going to be started when you have stopped SAP.
    > you want to stop  brarchive with option -f running? try:
    >
    > brarchive -f stop
    This is what is currently done right now.
    It works well.
    I can use it because we do a single copy of the archive log up to now.
    We are going to run two brarchives (one to save to a tape robot with backint and one that scp).
    I would like this to run as daemon.
    Now, that you have answered that I can not have two brarchives running at the same time (thanks for your answer),
    I need to write my own daemon in sh or perl that would do:
    1. Run brarchive first run (with -p backint init<SID>.sap file)
    2. Wait for the en of the brarchive process and log
    3. Run brarchive second run (with -p scp/stage init<SID>.sap file)
    4. Wait for the end of the brarchive process and log
    5. Sleep during a few minutes
    6. Handle stop signal so that it ends the forked brarchive that may be running.
    I am sure that people on this forum have already wrote such scripts.
    I may open another thread as it divert a little from my original question.
    Thanks in advance for your help.

  • FRM: 10270 Cannot attach the library when two forms run at the same time

    I get the error message FRM: 10270 Cannot attach the library SYSLIB while opening menu BMENU but only when i try to open a second form while the first form is still running.
    Both forms are working fine as long as they ar not running at the same time.
    It seems like the second form opening does not have access to the FORMS60_PATH, because you can not open a third form because it can't find it.
    All the forms anf libraries (plx)is in the FORMS60_PATH.
    I am running developer_6i forms & reports on a HPUX 11i machine and I am trying to access them through jinitiator 1.3.1.9 on a XP machine.
    Best regards
    Macke

    Thanks a lot for the tip. I used truss and realised that it found the library but was not allowed to open it. The kernel parameter maxfiles was set to low.
    I increased it and everything works ok
    BR
    Marcus

  • Two seperate animations running at the same time

    Hi
    I would like to make a fully automated presentation, with some object moving and the like... I am trying to have two seperate animations running on the same slide. The animations are quite simple - move in, move around, move out. What I would like is that they both act seperately so they start at the same time, but otherwise begins to move at different times and exits at different times. I'm having trouble achieving this as i can only link automatic actions to the last action on the list (i.e. I can't have two trees of actions that start simultaneous)
    I hope I have succedes in complicating an otherwise straightforward question with my late-at-night english

    You'll have to be more imaginative with the way you structure the builds so you can in fact do it inside one tree. (Not a put down, just it's hard to give more exact answer because the question has few specifics).
    Remember you have +*delay options*+ for each build, so two concurrent build/move actions can actually occur at different times in the presentation. Play with the start build and delay controls and you should be apples.

  • Getting 'Paint' and 'Sales History' to run at the same time

    Hi,
    Is this a matter of setting up a port for Paint and another for SH? Is there a limit to the number of OBI repositories that can be running at the same time?
    Thanks!

    Thanks.
    Can two or more repositories exist in the same rpd file? Can Paint and SH be in the same rpd file and be used by seperate groups that access completely different data sources?
    In our case, the dimensions and facts for glass used in a car are very different from the dimensions and facts for a car's transmission. There are similarities, true, but they are still very different.
    So, in one rdp file can there be seperate presentation folders for Glass, Tires, Transmissions, Seats, Axil, Engine, Steering Wheels, Head Lights, and etc...
    Each presentation folder would be used by different people. Each presentation folder would access different tables. The Glass Parts business will use the Glass presentation folder, the Axil Parts Guys will only use the Axil Presentation Folder, etc..
    As always, thanks!

  • Two processes running at the same time in Lookout

    I have installed Lookout 5.0 with 200 I/O Points onto our server computer. The application of motion control is next to the 200 I/O points through OPC PMAC server/client. Now I would like to have a second process in the same server for trouble shooting and testing without stopping the motion control process. However, this second testing process could have also many I/O points through Serial and USB ports. I assume that the total amount of I/O points of both processes will be greater than 200.I prefer to have independent processes for control and testing because access levels. Can I have these two processes running at the same time when needed?

    Hi,
    From your description you are using a third party OPC server for the motion application. You could have a second Lookout process communicating with the same OPC server with no problems, as long as you do not exceed the number of I/O points your license supports.
    Also, the process you are using for testing obviously could not overwrite datamembers (or registers if you will) that would interfere in the overall application, in other words you can test your application as long as you keep the coherency of the test.
    So the answer would be, yes it is possible, however you are still limited to the number of I/O's your license supports... You may even consider upgrade the number of I/O's you have in your license.
    Best Regards
    Andre Oliveira

  • Multiple scripts running at the same time?

    Is there a way to have multiple scripts successfully running at the same time?
    At the moment if I start a second script while the first one is still running, the second one completes successfully but the first one stops. This seems to be because the first one is no longer the active document once the second one opens so can't continue.
    Is there another way to script things like this so that multiple can run independently at the same time? You might ask why I'd want to run two at the same time and not just wait, but i've setup an asp.net web form front end and having problems if two people click the button around the same time.
    I'm guessing this isn't going to be possible and i'm going to have to look for ways of doing this in asp.net instead and somehow queue the requests so you have to wait longer if the script is already running?
    Thanks,
    Andy

    I'm
    guessing this isn't going to be possible and i'm going to have to look
    for ways of doing this in asp.net instead and somehow queue the requests
    so you have to wait longer if the script is already running?
    This is correct. The scripting interface to PS is single-threaded so you will need to queue up requests.

  • Can a vodcast and a photocast run at the same time ?.

    Hi,
    I would like have a video podcast play and a photocast run at the same time is this feasible?
    Geoff

    Since they're different apps and there's no way to sync something like that: no. Sounds like you could just do a video slideshow to me. That's supported by all major video creation apps.
    -S

  • Getting two midi threads to start at exactly the same time

    Hello, is it possible to get two threads to start at exactly the same time because when I start two threads or more at the same time that playback midi using a synthesizer, they never start at exactly the same time.
    Any help would be appreciated.

    Use the Behavior framework for making changes in the scene. This uses an internal j3d thread which is in sync with the rendering thread.
    See chapter 4 (Interaction) and 5 (Animation) in the 2nd module of the j3d tutorial (this may not be the correct chapters, since i have a rather old version of the tutorial)

  • Multiple Libraries for Video running at the same time on one PC

    Hi Everyone -
    I want to clarify this is for VIDEO files, not music for my 6 ATV's on the network.
    Problem: I have well over 1000 VIDEOS in my iTunes Library, and I am wanting to have multiple libraries availible at the same time; not just whichever the computer has open.
    We have several atv's on the network and I would like to take my video organization one step further; instead of scrolling forever in the atv menus for the video you want; I could make several libraries all availible at the same time. 
    Such as:
    Kids Library
    Workout Library
    Parents Library
    etc
    This in turn would shrink the primary library and have less videos to sort by.  I know how to create the Libraries, I just dont know how to have them all running at the same time.
    Infastructure:
    Windows 7 Ultimate with Drobo B800FS (16TB of storage) all connected to Cisco 3660 Gig switch with multiple atv's hardwired back.

    iTunes can only open one library at a time. If you have multiple computers, or virtual machines, each could be serving a different library.
    tt2

Maybe you are looking for