• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

SCJP Thread Gotchas

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can some people please help me collate a list of all the little tricks that the SCJP 5.0 tries in regards to thread questions. Thread questions are apparently some of the trickiest questions on the exam so I'd love to have an effective checklist to go through before I spend considerable time solving the thread questions on the exam. Currently I only have a few on my list:

1. Declaring a classes constructor as synchronized (Complier Error).

2. Class that extends thread does not have a constructor that matches one from the thread class (Compiler Error).

3. Having a static method which has a synchronized(this){} block (A static method does not have access to this and as such this will result in a Compiler Error).

4. Using a local string variable as a lock inside the run method (As a string pool will be used all instances of the local variable will be the same object unless new String("S1"); is used).

I'd love to get a few more contributions to this list, especially from those who have taken the real exam.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Look at interrupt(), isInterrupted(), sleep() in depth. How they work.
I found questions regarding them very tricky in the exam. One should be
very careful in that, as I think.



Thanks,
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jared Folino:
2. Class that extends thread does not have a constructor that matches one from the thread class (Compiler Error).


This is not correct. Since Thread has a default constructor, the compiler will be happy with any or no constructor.
 
Jared Folino
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about number 2. I was a little bit vague in my description. Say:



This code will not compile because Test is being invoked with a constructor it does not have.

So maybe I should rephrase it a little to:
Make sure that the class that extends Thread is invoked using one of it's declared constructor and not the superclasses constructor(Thread).

I've fallen for that trick in one of the Whizlab practise exams
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jared Folino:
This code will not compile because Test is being invoked with a constructor it does not have.

Ok. But remember that this is not thread specific. You could find this everywhere.
 
Do not threaten THIS beaver! Not even with this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic