Quick Q: Are thread nested?

consider this:
Thread thread1 = new Thread(new Runnable(){
    Thread2.start();
}).start();
thread1.sleep(100000);Will thread 2 continue unimpeded?
I would have assumed it would, as its kinda the point of threads as i understood them, but im having some unexpected behaviour, and clarification on this point will aid me with debugging.
Thank you

JamesBarnes wrote:
Ahh i see, that makes sense.
OK, with that in mind, i want a thread to perform a check every now and then (generally ~5minutes), would it be be bad practice to do the following?
new Thread(new Runnable(){
private void run(){
while(true){
if( timeElapsedSinceLastCheck > interval ){
perform check and respond
}).start();
If you don't put a sleep() inside that loop, then, yes, very bad idea.

Similar Messages

  • Are static nested classes thread-safe?

    There doesn't seem to be any definitive answer to this. Given the following code, is it thread-safe?
    public class SomeMultiThreadedWebController {
    public HttpServletResponse someMethodToExecuteViaWebRequest(HttpServletRequest request) {
        simpleQueryBuilder("SELECT...").addParameter("asdf","asdf").createQuery(EMF.getEntityManager()).executeUpdate();
    protected static class SimpleQueryBuilder {
             private String queryString;
             private Map<String, Object> params = new HashMap<String, Object>();
             public SimpleQueryBuilder(String queryString) {
                  this.queryString = queryString;
             public SimpleQueryBuilder addParameter(String name, Object value) {
                  params.put(name, value);
                  return this;
             public Query createQuery(EntityManager em) {
                  Query query = em.createQuery(queryString);
                  for (Entry<String, Object> entry : params.entrySet()) {
                       query.setParameter(entry.getKey(), entry.getValue());
                  return query;
        public static SimpleQueryBuilder simpleQueryBuilder(String queryString) {
             return new SimpleQueryBuilder(queryString);
    }Forget whether or not someone would do this, as this is just an example. I'm really trying to get at whether or not the instance variables inside the static nested class are thread-safe. Thanks for any responses.

    Hello,
    I believe you understand what you're talking about, but you state it in a way that is very confusing for others.
    Let me correct this (essentially, incorrect uses of the terminology):
    I agree that thread-safe or not is for an operation, for a member, it has some sort of contextual confusion.
    Member has a much broader meaning in the [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4] . Even "class member" applies to both an attribute, a method, or an inner class or interface.
    I think you mean "member variable" of a class (aka "attribute" or "field"). By the way, static or not is irrelevant to the rest of the discussion.
    For an operation or a member, if there's only one thread could access it atomically in one moment, we could call it thread-safe.Mmm. I was tempted to say yes (I'm reluctant to commit myself). With an emphasis on "_The encapsulating class_ makes this member's usage thread-safe".
    Still, just synchronizing each operation on a member is not enough to make all usages "thread-safe":
    Consider a java.util.Vector: each add/get is synchronized, so it is atomic, fine.
    However if one thread adds several values, let's say 3, one by one, to a vector that initially contains 0 values, and another thread reads the vector's size() (another properly synchronized method), the reader thread may witness a size anywhere among 0, 1, 2, 3, which, depending on the business logic, may be a severely inconsistent state.
    The client code would have to make extra work (e.g. synchronizing on the vector's reference before the 3 adds) to guarantee that the usage is thread-safe.
    Thus any synchronized method(With the limit stated above)
    or immutable member (like primitive type) are thread-safe.
    Additionally for a member, if it's immutable, then it's thread-safe. You mean, immutable primitive type, or immutable object. As stated previously, an immutable reference to a mutable object isn't thread-safe.
    a static final HashMap still have thread-safe issue in practice because it's not a primitive.The underlined part is incorrect. A primitive may have thread-safety issues (unless it's immutable), and an object may not have such issues, depending on a number of factors.
    The put, get methods, which will be invoked probably, are not thread-safe although the reference to map is.Yes. And even if the put/get methods were synchronized, the client code could see consistency issues in a concurrent scenario, as demonstrated above.
    Additional considerations:
    1) read/write of primitive types are not necessarily atomic: section [ §17.7 of the JLS|http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7] explicitly states that writing a long or double value (2 32-bits words) may not be atomic, and may be subject to consistency issues in a concurrent scenario.
    2) The Java Memory Model explicitly allows non-synchronized operations on non-volatile fields to be implemented in a "thread-unsafe" way by the JVM. Leading way to a lot of unintuitive problems such as the "Double-Checked Locking idiom is broken". Don't make clever guess on code execution path unless you properly synchronize access to variables across threads.
    Edited by: jduprez on Mar 4, 2010 9:53 AM

  • How can I remove the Quick Launch area from a SharePoint site

    We have a SharePoint site that includes a Quick Launch area by default.  We know how to add and delete items from the Quick Launch area but how can we delete the Quick Launch space (this would shift the main body portion over to the left and taking
    over the space once occupied by the Quick Launch area)?

    Hi,
    You can refer the below urls.
    http://sharepointpolice.com/blog/2010/04/07/hiding-the-quick-launch-in-sharepoint-2010/
    http://chrisstahl.wordpress.com/2010/03/15/hide-the-quick-launch-in-sharepoint-2010/
    http://sharepointpromag.com/sharepoint/four-ways-add-or-remove-quick-launch-menu-control
    Please remember to mark your question as answered & Vote helpful,if this solves/helps your problem.
    s p kumar

  • How to pin a website's icon to the quick launch area.

    ''duplicate - https://support.mozilla.com/en-US/questions/901878''
    I'm used to the Internet Explorer option to create a shortcut to the desktop, then I drag the icon to the quick launch area. I don't see that option in FF.

    You can drag the favicon on the left end of the location bar onto the desktop to create a shortcut.
    You can also use an extension.
    * SaveLink: https://addons.mozilla.org/en-US/firefox/addon/savelink/
    * Deskcut: https://addons.mozilla.org/en-US/firefox/addon/deskcut/

  • Are threads in the application server preemptive?

    Are threads in the application server preemptive or non-preemptive? That is do
    they automatically yield to other threads running in the application server after
    they have run for a certain amount of time or do they only yield when certian
    points in the code are reached (eg when they have completed, when they reach a
    remote call or when they explictly call yield()).

    Green threads (way back in 1.1.8 and so on) was Unix only, and non-preemptive.
    It was also very lumpy and unreliable. Old threading tutorials used to recommend
    calling yield() and suitable points in your code - just like Windows 3.0 all over
    again.
    But all current JVM implementations use OS threading, and are pre-emptive (but
    of course that doesn't stop them being blocked due to synchronization or I/O etc...)
    simon.
    Rob Woollen <[email protected]> wrote:
    It would depend on the underlying JVM or OS. However I've not aware
    of any Java
    implementations that are non-preemptive.
    -- Rob
    Ash Beitz wrote:
    Are threads in the application server preemptive or non-preemptive?That is do
    they automatically yield to other threads running in the applicationserver after
    they have run for a certain amount of time or do they only yield whencertian
    points in the code are reached (eg when they have completed, when theyreach a
    remote call or when they explictly call yield()).

  • How to open closed quick launch area in hana modeler?

    how to open closed quick launch area in hana modeler?

    Hello Abhinay,
    Open SAP HANA studio, go to window -> open Perspective-> SAP HANA modeler. Quick launch view will be opened.
    OR
    Go to window -> show view -> others . Type quick launch in serach. or under SAP HANA folder you will get the quick launch view option.
    Regards
    Subhash

  • What are JAVA API are threaded in default list plz

    hi every body
    Can u give me List of JAVA API are threaded default

    Can u give me List of JAVA API are threaded default1. Java is not an abbreviation.
    2. What do you mean?

  • What are thread records ??

    what are thread records ?

    armadillotimes:
    It is a fairly serious directory problem which Disk Utility is not able to fix. Disk Warrior or Tech Tool Pro may be able to repair it. If they can't you will have to reformat your drive and reinstall.
    Good luck.
    cornelius

  • Feeling pretty stupid.... quick brushes are greyed out

    well, using aperture 2 for years, I figured "how hard can 3 be??" well, my quick brushes are all greyed out except "retouch". Anybody have any ideas how to get the tools back? D300 is on approved list, so that's not it...

    okay I have part of the problem solved. There was this warning "this photo was adjusted with an earlier version of aperture. There is a "reprocess" dialogue box beside it. Well, once "reprocessed" the quick brushes showed up. Now the picture I imported today hasn't been in any Aperture except this version 3. What's up with that?

  • Quick Brushes are disabled on most images

    Quick Brushes (all except for Retouch) are disabled on most images in my libraries. Some images the brushes are enabled and work fine.
    The images are a mixture of mostly RAW images from a Canon 10D and a 7D. So far I haven't identified any pattern that suggests the camera origin makes any difference––some from each camera work, but most don't.
    Any ideas? This is pretty frustrating. Unless I figure something else out, my next step is to uninstall / reinstall Aperture. Thanks for any help!

    Problem solved!
    Images for which Quick Brushes were disabled were processed using an earlier version of Aperture. When editing an image, the top of the Adjustments showed a little box with this statement and a button to reprocess the image. You can also select any number of images in the browser, right click on them, and select "Reprocess Master." Reprocessed images immediately have access to the full Quick Brushes menu.

  • Quicker photos are being skipped in playback ??? and export problem

    The photos in my project that are around 00:00:00:10 and less are being skipped over when i replay everything. A few of the photos need to be set at a quick speed so i can get a moving stop animation effect. Can anyone help me with this problem, it would be greatly appreciated. Also when i export the video as a quicktime file and play it, only goes for 2 seconds? The total duration should be 1min. I have also double checked that i dont have anything specifically selected. HELP ME PLEASE !

    Need some detail: photo height and width, seqeunce settings, export settings, which Premiere version and comp specs.

  • Audio tracks are not nesting

    So all of a sudden, when I select the audio and video clips and right click > Nest....only the video tracks are being replaced by the nested sequence on the timeline while the audio clips stay intact on the timeline.  When I look at the nested sequence all the audio clips have been copied there. 

    Ok, I'm officially upgrading this bug. Now, in Adobe Premiere Pro CC 2014, when I use the "Nest" command I get the same behavior as mentioned above. Except now when I drag the nest into a time line, it acts like the nest is not there and instead drags all the tracks in (6 tracks). Even if I try to drag a sequence into another sequence, it instead drags it in not as a nest, which is something I definitely do every day in CS6, but instead as all the separate tracks.
    At this point, I'm starting to feel a bit like a beta tester on an unreleased product. Just a few more of these bugs and I'm going to have to go back to "last years model" CC until an update for 2014 is released.

  • Fixed and 2 quick questions (bios thread)

    Hi Everyone, i need your help again...
    [....]. since i installed Win2k3 on my system i was getting stability problems, especially lockups to black screen in games. On Win2k3 i was using the exact same drivers as I am going to list soon, and so I thought I'd install Windows XP again on a spare hard drive to see if this helped. I wish i'd never messed with my system my previous XP install was almost 100% stable, but that's another  story.
    Today I perfomed these steps in this order:
    1)Downloaded SP1a
    2)formatted new hard drive
    3)Booted from CD, did a Windows XP Pro install
    4)Started XP Pro, installed SP1a
    5)Installed Nforce system drivers and Display Drivers 29.42 (these were very good to me before...) and restarted
    6)Installed Speedtouch USB ADSL Drivers 2.0.1.2 and went online
    6.5)Enabled Hardware Acceleration on Displayt Properties
    6.7) Installed direct x 9.0a web setup.
    7)Did full windows update: all the critical stuff, most of the recommended (except MEssanger, Media Player and a couple others) and the CPU driver (left my Gfx and Sound on the above)
    8) After a restart started a game
    It lasted all of 10 seconds once I started playing.
    Ok, maybe 5 seconds. Smae as Win2k3!!! I was running bios default performance options, with APIC off... so I ran Prime 95 for a while, got no errors .... about to try a memtest86 but I'm pretty cetrain the memory is good never had trouble with it before at all and I've tested it before too.
    Can someone help me out? Here's my hardware config
    [size=11]
    AMD XP 1900+ (no overclock any more)
    MSI K7N420D MB
    2*512MB DDR266 Samsung 'Transcend' Memory (unbranded really) (16 chip DIMMs)
    Geforce 2 MX400 32MB SDRAM (unbranded - runs a little faster then onboard graphics)
    Adaptec 29160LP Scsi Card
    IBM 16000rpm 32GB SCSI Disk (UW-2)
    2*WD1000BB 100GB Western Digital IDE Drives (the normal ones with 2mb cache) in Software Raid - 0 on Promise card
    18GB Maxtor ATA66 IDE hd on Nforce, with CDR.
    a Promise Ultra TX100 Dual IDE Controller card (for CD Rom + expansion)
    Enermax 431w PSU / 7200rpm fan on heavy HS.
    Windows XP SP1 / DX 9.0a (going to reformat to Win2003)
    [/SIZE]
    I could really do with anyone's working driver config for a windows XP sp1a system, and how to build it from the bottom up. If a given driver config that works 100% for others fails for me I can start hardware troubleshooting and cursing loudly, otherwise with any luck it'll fix my problem.... please help me out i know there are people out there still running NForce 1 boards!
    Quick question that could help: what sound driver revision from windows update should i be using? I can get the archived ones....
    Thanks,
    Naveen.
    PS If i manage to fix it i'll update here, but i need a hand plz

    .... also, I have the same errors running the same game from Win2k3 on a SCSI drive through the PCI bus (adaptec 29160) on the 2.7 bios. It looks like there is still an issue with fast PCI bus read/writes, sound usage and AGP card usage causing crashes. Discounting the OS change and APIC, I have these scenarios:
    1) Game running off IDE drive on Nforce IDE ports: fine
    2) Running of IDE drives on promise controller card: fails, locks.
    3) Running off scsi drive on Adaptec 29160 card: fails, game locks.
    So we may still have an issue with PCI read/writes and stability on bios 2.7 and Nforce system drivers 2.03 ... which is big news really.
    I hope one of the moderators can put MSI in the picture and get them or NVidia to look into this. I can try eliminating APIC and the OS/Drivers from the issue, and install the game on all 3 drive configurations to confirm the above if necessary, but it's what it looks like from here. Using Performance bios defaults with no overclock, underclocking didnt help.
    Perhaps bios 2.4 will fix this in which case the bios still needs work, 2 years on.
    Naveen

  • Please confirm that stubs are thread-safe

    Can someone please confirm that if one is to invoke the same remote method from more than one thread in a client application that one does not need to get multiple remote stubs for the same RMI server object. As long as the implementation of the remote method is thread safe, everything okay, correct?
    In otherwords, are remote stubs them selves thread safe? I always assumed they were.
    Thanks in advance

    Stubs are threadsafe. The reason is that a second concurrent invocation via the same stub will use a new TCP connection. I took this up with Sun once and the response was along the lines 'if it doesn't say it isn't thread-safe, it's thread-safe'.
    It's the method implementation at the server that isn't thread-safe, unless you make it so.

  • Quick Polls are not shown

    Hi,
    we have a problem with the quick poll functionality.
    After creating a qick poll and activating it, it is not shown in the user's start page. When editing the poll, the quick poll is shown in preview mode and it is also possible to do a voting.
    What can we do?
    Thanks in advance.

    Hi Thomas,
    check, if you Quick Poll is saved in the KM folder "/documents/QuickPoll". If it is not you have to change the properties of that iView for that startpage. Check also the name of the campaign in that iView and in the Quick Pole you have create that they are all the same.
    You can find it in the PCD under Portal User/Standard Portal Users/ Standard Userrole. Edit that role to check and to edit this belonged iView.
    Hope that helps,
    Frank

Maybe you are looking for

  • How do I get Time Machine to back up my iTunes movies and tv shows?

    How do I get Time Machine to back up my iTunes movies and tv shows?

  • How do I get rid of iCloud spam

    I've recently been receiving ban enormous amount of spam from my iCloud mail account. What can be done about this?

  • Quicktime x will not open

    I think I have a file association issue. I have a piece of paper and pencil for a quicktime x icon and quicktime will not open. I have tried to look for ways to uninstall and reinstall quicktime x but I am new to the Macbook Pro so I'm not familiar o

  • How to create staing area

    Hi, I have downloaded oracle 11i software from edelivery and try to create staging area. Do we need to run adautostg.pl or just unzip all file in one directory? If I am run adautostg.pl script, it ask me mount DVD which I don't have. And if I am tryi

  • BW Bex Browser in SAP GUI for JAVA 6.40 R2.2 for Linux Desktops

    Hello, I am using SAP GUI for JAVA v 6.40 R2.2 on a Linux desktop. But during the installation it doesn't ask for BW Bex installation option (as in SAP GUI for Windows). Is it the case that BW Bex is not supported in Linux Environment? If it is then