How to print 1 to 100 using threads

Hi,
I have 5 threads (t1, t2, t3, t4, t5) and I want to print the values as
t1 - 1
t2 - 2
t3 - 3
t4 - 4
t5 - 5
and again
t1 - 6
t2 - 7 and goes on upto t5-100 and the condition is that it should print
as 1,2,3,4,5,6,7,...,99,100.
Any help would be greatly appreciated

What aboutimport java.util.Stack;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ConcurrentCounter implements Runnable
     private static volatile Stack<Integer> stack = new Stack<Integer>();
     public static void main(String[] args) {
          for (int i = 100; i >= 0; i--) {
               stack.push(i);
          ExecutorService executor = Executors.newFixedThreadPool(5);
          for (int i = 0; i < 5; i++) {
               executor.execute(new ConcurrentCounter());
          executor.shutdown();
     public void run() {
          while (true) {
               synchronized(stack) {
                    if (stack.isEmpty()) break;
                    System.out.println(Thread.currentThread().getName() + ": " + stack.pop());
               try {
                    Thread.sleep(100);
               } catch (InterruptedException e) {
                    // ignore
}

Similar Messages

  • How to print uspto patent images using Safari and Quicktime

    3/18/06
    Do you want to know how to print US patent images using Safari? Read on.
    When you access the "images" link of a specific patent on the www.uspto.gov/ website using Safari, the page you are viewing is only one small upper left tile of a huge patent image that is not sized to the screen. You can scroll and try to read the page but it's almost impossible. Try to print it out and you only print what's on the screen. Bummer.
    The fix:
    Place the cursor on the opened image (it may appear blank), hold down the CONTROL key on you keyboard and click on the image. Two instructions come up. Click on the "Save Image to the Desktop" instruction and a DImg.tiff file will be created on your desktop. Click on the .tiff file and it should open in the Preview program, then simply print out the image. Voila!!!!
    Click the yellow arrow in the left margin to access page 2 of the patent and repeat the previous instructions to create another .tiff file on your destop. Do every page and you'll have the patent available to print out one page at a time.
    You can then rename the files and create a folder for that specific patent so you can access it later without signing onto uspto site.
    It's odd that the ever compatible Apple does not provide seamless compatibility to view and print patent images on the US Patent and Trademark Office's website. Where would they be without protecting their own intellectal property? Let's hope the next version of Quicktime includes the appropriate ITU T.6 or CCITT Group 4 (G4) compression language.
    Even the "throw it out the Windows" operating system is up to speed on this issue for America's hard working inventors.
    Keep on inventing.
    Tommy K
    imac 400 DV   Mac OS X (10.3.9)   Cube 450
    imac 400 DV   Mac OS X (10.3.9)   Cube 450

    Another similar thread on this issue...
    http://discussions.apple.com/thread.jspa?messageID=1602391

  • How to print text on container using oop on alv list

    Hello Guru's,
             pl guide me how to print text on container using alv list-display which have interactive events  using     oop classes/methods ...
                    I want to print hard coded text on coantainer , on double clicking it will call another screen.
    Pl Help..
    Message was edited by:
            paresh sonavane

    Hi Paresh,
           1.      Go to the Layout and Create One custom container box and give name it.
            2. Custom Container is the one type of tool and its used for Displaying the Reports 
                with the use of ABAP Objects.
            3. Go to se38 and Write The Following Code.
    tables ZTEAM_GD.
    DATA : OBJ TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
           OBJ1 TYPE REF TO CL_GUI_ALV_GRID.
    DATA IT_TEAM LIKE TABLE OF ZPLAYER_BAT_DET       .
    SELECT * FROM ZPLAYER_BAT_DET INTO TABLE IT_TEAM.
    CREATE OBJECT OBJ
      EXPORTING
        CONTAINER_NAME              = 'ALV'.          -
    > Give ur Container Name
    CREATE OBJECT OBJ1
      EXPORTING
        I_PARENT          = OBJ.
    CALL METHOD OBJ1->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME              = 'ZPLAYER_BAT_DET'
      CHANGING
        IT_OUTTAB                     = IT_TEAM.
    *CALL METHOD OBJ1->SET_DROP_DOWN_TABLE
    EXPORTING
       I_STRUCTURE_NAME = 'ZTEAM_GD'
    CHANGING
       IT_OUTTAB        = IT_TEAM.
    CALL SCREEN 9000.
    *&      Module  USER_COMMAND_9000  INPUT
          text
    MODULE USER_COMMAND_9000 INPUT.
    CASE SY-UCOMM.
    WHEN 'EXT'.
      LEAVE PROGRAM.
    ENDCASE.
    ENDMODULE.                 " USER_COMMAND_9000  INPU     
    Thanks.
    Reward If Helpful.

  • Can anyone help how to print stack trace messages using log4j?

    Can anyone help how to print stack trace messages using log4j?

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    </appender>
    <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-debug.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="DEBUG" />
    <param name="LevelMax" value="DEBUG" />
    </filter>
    </appender>
    <appender name="INFO" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-info.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="INFO" />
    <param name="LevelMax" value="INFO" />
    </filter>
    </appender>
    <appender name="WARN" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-warn.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="WARN" />
    <param name="LevelMax" value="WARN" />
    </filter>
    </appender>
    <appender name="ERROR" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-error.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="ERROR" />
    <param name="LevelMax" value="ERROR" />
    </filter>
    </appender>
    <root>
    <priority value="debug"/>
    <!--<appender-ref ref="STDOUT"/>
    --><appender-ref ref="DEBUG"/>
    <appender-ref ref="INFO"/>
    <appender-ref ref="WARN"/>
    <appender-ref ref="ERROR"/>
    </root>
    </log4j:configuration>
    I ve written like this
    and to print stack trace I used
    log.error(Throwable(e))
    but does nt display printstacktrace how to do it

  • How to print logo in printout using classical report.

    Hello Friends,
    By using below code i am displaying logo in output using Classical report.
    What my problem is it is not displaying in print out.
    Please help. or else tell me how to print logo in classical report as well as output print out.
    DATA: docking TYPE REF TO cl_gui_docking_container,
          picture_control_1 TYPE REF TO cl_gui_picture,
          url(256) TYPE c ,
          query_table LIKE w3query OCCURS 1 WITH HEADER LINE,
          html_table LIKE w3html OCCURS 1,
          return_code LIKE w3param-ret_code,
          content_type LIKE w3param-cont_type,
          content_length LIKE w3param-cont_len,
          pic_data LIKE w3mime OCCURS 0,
          pic_size TYPE i,
          repid LIKE sy-repid.
    repid = sy-repid.
    START-OF-SELECTION.
      CREATE OBJECT picture_control_1
        EXPORTING
          parent = docking.
      CHECK sy-subrc = 0.
      CALL METHOD picture_control_1->set_3d_border
        EXPORTING
          border = 5.
      CALL METHOD picture_control_1->set_display_mode
        EXPORTING
          display_mode = cl_gui_picture=>display_mode_stretch.
      CALL METHOD picture_control_1->set_position
        EXPORTING
          height = 100
          left   = 700
          top    = 1
          width  = 200.
      "Position
      IF url IS INITIAL.
        REFRESH query_table.
        query_table-name = '_OBJECT_ID'.
        " Logo Name
        query_table-value = 'ENJOYSAP_LOGO'.
        APPEND query_table.
        CALL FUNCTION 'WWW_GET_MIME_OBJECT'
          TABLES
            query_string        = query_table
            html                = html_table
            mime                = pic_data
          CHANGING
            return_code         = return_code
            content_type        = content_type
            content_length      = content_length
          EXCEPTIONS
            object_not_found    = 1
            parameter_not_found = 2
            OTHERS              = 3.
        CALL FUNCTION 'DP_CREATE_URL'
          EXPORTING
            type     = 'image'
            subtype  = cndp_sap_tab_unknown
            size     = pic_size
            lifetime = cndp_lifetime_transaction
          TABLES
            data     = pic_data
          CHANGING
            url      = url
          EXCEPTIONS
            OTHERS   = 1.
      ENDIF.
      CALL METHOD picture_control_1->load_picture_from_url
        EXPORTING
          url = url.
      WRITE : /'Classical Report Logo'.
    Regards,
    Phaneendra
    Edited by: phaneendra punukollu on Dec 31, 2009 11:38 AM
    Code Formatted by: Alvaro Tejada Galindo on Jan 4, 2010 4:52 PM

    Hello Nidhi,
    Thanks for your sugessition.
    Actual we have data from IDOCS and it is maintained in Ztables
    and need to dispaly in report ( Service centre - Warranty data ).
    The report is completed. So again going to Script means waste of time for us.
    So Plz help me  if possible in Classical report.
    Regards,
    Phaneendra

  • How to print a text file using Java

    How can I print a text file using Java without converting the output to an image format. Is there anyway I can send the characters in the text file as it is for a print job? I did get a listing doing this ... but that converted the text to an image format before printing....
    THanks,.

    Hi I had to write a print api from scratch, and I did not convert the output to image. Go and read up on the following code. I know there is a Tutorial on Sun about the differant sections of the snippet.
    private void printReport()
         Frame tempFrame = new Frame(getName());
         PrintJob printerJob = Toolkit.getDefaultToolkit().getPrintJob(tempFrame, "Liesltext", null);
         Graphics g = printerJob.getGraphics();
                    //I wrote the method below for calculations
         printBasics(g);
         g.dispose();
         printerJob.end();
    }This alone wont print it you have to do all the calculations in the printBasics method. And as I said I wrote this from scratch and all I did was research first the tutorial and the white papers
    Ciao

  • How to print text rertrived by using the READ_TEXT fun module in smartform

    Please tell me how to print the text which is rertrived by using the READ_TEXT function module in smartform.
    I have coded all things in the program lines and in that i am retriveing the long texts.
    I am getting the text lines in my internal table clearly, the thing is that I am not able to pass these lines to the text module.
    its urgent. Points will be rewarded for any type of clue. whether it will work or not.

    loop the table into which u have retrieved the text .
    in the form interface of the smartform ... in importing parameter give the that table name .
    and in smartform whereever u want to print there insert the data into work area and pass to fields for dispaly .
    decalre ur work area in global defintions
    thnaks .

  • How to print a pdf @ 100% 10cm on screen = 10cm on print

    I cannot seem to print pdfs to any printer wireless or wired at 100%.
    If i put 100% and choose boarderless paper the print out is one size if i choose with boarder it prints out a different size.
    furthermore in both cases the print is not even 100% 10cm measured on screen will not be on either print outs.
    This has been driving me mad! i've played around with a few of the preview settings ie switching between 1 image pixel equals 1 screen pixel and size on screen equals size on printout.
    help

    In testing your symptom to a Canon MG6150 I get exact reproduction. I created a 10cm x 2cm box in InDesign and printed that at 100%. That measued correctly.
    I then exported the document to PDF and opened in Acrobat. With the ruler enabled I could see the box was 10cm x 2cm. And when I printed it with page scaling set to 100% the box was the correct measurement.
    As for the borderless vs border, my understanding of borderless is that it will enlarge the document to fill. Often in the driver settings you can adjust the amount of extension so this would impact your image reproduction.

  • How to print from the iPhone using my network printer

    I have just a regualar HP networked priinter, nothing fancy for iPhone printing.  I have tried Prnter Pro without sucess.  I'm looking for a way to print from my iPhone using my network. 

    HP has an app (free) that I use to print from my iOS device to an HP printer attached to my network.
    Barry

  • How to print pdf file not using the the adobe reader ?

    hello,
    i used the adobe sdk to open a pdf file in read and modify it serveral times and each time save it to another directory,and now i need to write a program to print the pdf file in this directory.when print the file,i want to continue my work also,so who i tell me how to solve this problem?
    thanks.

    The SDK is only a collection of documentation and headers that show you how to interact with and automate Adobe Acrobat and to some extent Adobe Reader. You need a copy of Acrobat or Reader installed on the system in order to use any of the SDK functions. You cannot "print not using the Adobe Reader", unless you have Adobe Acrobat installed on the system instead of Reader.

  • How to print pdf files not using acrobat product?

    i just want to print pdf files,but not want to use the adobe acrobat or acrobat reader,just want to write a tools print pdf files directly.

    > no i just want to print it,not need to read it.can you help me?
    Well, the problem is to print it you need to be able to read it. Something needs to convert it into a format the printer can understand (most printers are PostScript or PCL).
    I'm not sure you entirely understand what a PDF file is. It's not a fancy text file. It's a binary format. Saying "I want to print a PDF without a PDF interpreter" is like saying "I want to run an EXE without Windows". You need software to interpret the format.
    You certainly can write your own software to interpret the PDF format, convert it to a print language and output that to a printer, but as Aandi said you will need to start by reading the PDF Reference so you know how the inside of a PDF file works, and it will most likely take several years of development even for a seasoned, expert programmer. It's just not as simple as "Printer, meet PDF. PDF, meet printer."

  • How to print in PL Sql using a procedure?

    So how do you create a procedure to print a name in PL Sql ? Here is what I have done so far.
    Create Procedure Print_Info
    ( X_Name IN Varchar2
    ) As
    Begin
    :X_Name:='Anabella'
    DBMS_Output.Put_Line (X_Name);
    End Print_Info;
    thanks

    user8706975 wrote:
    So how do you create a procedure to print a name in PL Sql ? You cannot.
    PL/SQL is a server process. It is not connected or wired to a keyboard, mouse, screen or printer.
    The client process (SQL*Plus, TOAD. etc.) interfaces with the end-user - it is connected to peripheral devices like mouse, keyboard and screen.
    And this is exactly what client-server is. And which is why the task to "+Print data using PL/SQL+" is missing the fundamental concept of what client server is. It is utterly and totally flawed. And should you be doing this as some kind of course, then you should seriously question what they are teaching as the concept of PL/SQL printing anything is just plain bloody wrong.
    So how does DBMS_OUTPUT then works? The DBMS_OUTPUT package has a static buffer area (variable) that you can place data into using the put and put_line procedures.
    A client, like SQL*Plus, can then interrogate this buffer after executing PL/SQL code, and remove and display the content in that buffer to the end-user. This is not "+printing by PL/SQL+" just as running a SQL select from a client and viewing the data (in the client) is not "+printing by SQL+".
    It is very important that you grasp correctly what client-server is and the basics of how it works - as that will enable you to truly understand what PL/SQL is, what Oracle is, and how to correctly use it. It will enable you to understand how to troubleshoot performance problems, how to design systems optimally and so on. One cannot simply learn PL/SQL the language and expect to be a good Oracle developer. Understanding what client-server is and how it works in Oracle, is more important than to be an expert on a specific programming language. Knowing a programming language does not mean being able to architecture efficient and scalable solutions using that language.

  • How to print stacktrace in log using logging

    Hi All ,
                I am using logging in my webdynpro application
    I hv written following java class for logging
    ***************************************java class Starts *******************************
    public class ReferenceApplicationEJBLogger {
         private static final Location LOCATION = Location.getLocation("com.apl");
            private static final Category CATEGORY = Category.getCategory(Category.APPLICATIONS, "Reference Application");
       static{
               LOCATION.setMinimumSeverity(CATEGORY, Severity.INFO);
               LOCATION.setMaximumSeverity(CATEGORY, Severity.ALL);
               CATEGORY.addLog(new FileLog("./log/application/hrhelpdesk/edmProject.%g.trc"));
        public static void logException (Exception eMessage){
               logThrowable(eMessage);
               eMessage.printStackTrace();
             public static void logThrowable (Throwable eMessage){
               CATEGORY.logThrowableT(Severity.WARNING, LOCATION, eMessage.getLocalizedMessage(), eMessage);
        public static void logWarning (String logWarning, Exception eMessage) {
               CATEGORY.warningT(LOCATION, logWarning, new Object[]{eMessage});
             public static void logInfo (String logString){
               CATEGORY.infoT(LOCATION, logString);
             public static void logWarn (String logString){
               CATEGORY.warningT(LOCATION, logString);
    ***********************************Java class ends here **********************************
    and inside my webdynpro applicaiton i have written following code in side catch block
    ReferenceApplicationEJBLogger.logInfo("Error occured in application" );
    log is getting written in to defined locaiton ./log/application/hrhelpdesk/edmProject.%g.trc
    but i also want to print e.printStackTrce() in above mentioned location along with message "Error occured in application".
    How to go about it ? Thnx in advance
    Regards
    Kavita

    Let me understand first, are you looking at printing the complete exception log?
    catch (Exception e) {
              StringWriter sw = new StringWriter();
              PrintWriter pw = new PrintWriter(sw);
              e.printStackTrace(pw);
              System.out.println(sw.toString().toUpperCase());
    Tested, it works.
    Regards,
    Nitin
    Edited by: Nitin Mahajan on May 28, 2009 9:51 PM

  • How to print with "Scale: 100%" by default from Preview

    The print dialogue in Preview is set by default to "Scale to Fit".
    I never need this, I always need "Scale: 100%".
    It's annoying to change all the time I have to print a PDF from Preview the setting!
    I tried to save the print setting, but it does not work.
    So. Is there a way to set the print dialogue by default to "Scale: 100%" ?
    Mayby with a Terminal command?

    AFAICT, only for PDF files. If you want to report this issue to Apple's engineering, send a bug report or an enhancement request via its Bug Reporter system. To do this, join the Mac Developer Program—it's free and available for all Mac users and gets you a look at some development software. Since you already have an Apple username/ID, use that. Once a member, go to Apple BugReporter and file your bug report or enhancement request. The nice thing with this procedure is that you get a response and a follow-up number; thus, starting a dialog with engineering.

  • How to Print to a paper using PL SQL

    Hi All,
    I have some advice generated in the database. These are well formatted and to be printed on a pre-defined background template.
    Could you please tell me the best way to print them using PL/SQL code?
    I tried using some other technology but the formatting of the message gets lots in this.
    regards
    Suhel

    >
    I dont have to format the same.It is already formatted using some other code. I have to print As-it-is.
    >
    I sincerely doubt that.
    As-it-is means a simple read-a-line, print-a-line. Already formatted for what font? what font-size?
    What is it that controls how many lines are on a page? If the formatted data is set for 66 lines per page then you can just copy lines to the printer if the custom paper has 66 lines per page.
    What happens when you print?

Maybe you are looking for