Showing posts with label small talk programming interview questions. Show all posts
Showing posts with label small talk programming interview questions. Show all posts

schedule threads in java programming


 schedule threads in java programming
Java defines methods wait, notify, and notifyAll in the base class Object. The method wait is used when a thread is waiting for some condition that is typically controlled by another thread. It allows us to put a thread to sleep while waiting for the condition to change, and the thread will be wakened up when a notify or notifyAll occurs. Therefore, wait provides a method to synchronize activities between threads, and it is applicable to solve this problem.
A solution based on methods wait and notify is found in Listing 2-19. Listing 2-19. Java code to schedule threads
public class SimpleThread extends Thread {
    private int value;
    public SimpleThread(int num) {
        this.value = num;
start();
}
    public void run() {
        while(true) {
            synchronized(this) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.print(value + " ");
            }
} }
}
public class Scheduler {
    static final int COUNT = 3;
    static final int SLEEP = 37;
    public static void main(String args[]) {
        SimpleThread threads[] = new SimpleThread[COUNT];
        for(int i = 0; i < COUNT; ++i)
            threads[i] = new SimpleThread(i + 1);
        int index = 0;
        while(true){
            synchronized(threads[index]) {
                threads[index].notify();
}
            try {
                Thread.sleep(SLEEP);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
}
            index = (++index) % COUNT;
        }
} }
 There are four threads in the code above. The first is the main thread in the Java application, which
acts as the scheduler, and it creates three printing threads and stores them into an array. The main thread
awakens threads one by one according to their index in the array via the method notify. Once a thread
wakes up, it prints a number and then sleeps again to wait for another notification.
Source Code:
   004_Scheduler.java
www.cinterviews.com appreciates your contribution please mail us the questions 
you have to cinterviews.blogspot.com@gmail.com so that it will be useful 
to our job search community    
   
  
 

smalltalk interview faqs

1. What was the original assignment operator in Smalltalk-80?

2. What does the #at: method of a collection class return?

3. What does the #at:put: method of a collection class return?

4. What is a "first class object"?

5. Tell me about block variables, arguments, and scope of variables.

6. Explain smalltalk mathematical notation, including order of operations and 
 the reasons.

7. Why can't you do recursion in Smalltalk?

8. What is the difference between an instance variable, a class variable, and 
 a class instance variable?

9. Describe indexed instance variables vs. named instance variables.

10. How do you access indexed instance variables?

11. What is a meta-class, and what objects are instances of meta class?

12. What is an abstract class?  Can you name an example in Smalltalk?

13. How does Smalltalk support multi-tasking?

14. Name some examples of how Smalltalk is oriented toward single users?
How can these problems be approached or overcome?

15. Suppose you were offered the choice of two tasks with the same tight deadline:
                                (1) Write a Smalltalk to C++ cross compiler
                                (2) Write a C++ to Smalltalk cross compiler.
                     
                        Which task would you choose and why?

16. Name some of Smalltalk's shortcomings.

17. What is the value of n after the following code is executed? 
                 | n |
                 n := Dictionary new.
                 n at: #one put: 1.
                     
                 Evalutate the coding style of the above Smalltalk code.

18. In which of the following languages can the programmer know the type of 
 data a variable will refer to at runtime:
                        C, C++, Smalltalk

19. Which of the following phrases could be applied to Smalltalk?
untyped, statically typed, dynamically typed, strongly typed, weakly typed 

20. What is meant by the word "binding" with respect to data elements?

21. Most people would agree that it is inherently easier to implement a 
 Dictionary class in Smalltalk than in C/C++.  Any reasonable C++ 
 implementation would also be trickier to use.  Why?