MN falters

  MSN MSN falters this day life and death falters, depressed.    A lot of online search data will not solve the problem.    Posted on 2005-05-14 21:32 tip of reading (49) Comments (0) edit collections cited 

PringMVCĵÃ

  SpringMVCĵà

  ÔSimpleFormControllerý 
  1 £ spring һ Ո ȕ Д à "get" ߀ Ç "post" ¨ 

  2 £ 1 "get" • r 
  ????????? 2 £ 1 £ 1 Ȅ һ

Database fields, as well as increase the display

  Database fields, as well as increase the display 

  Following nearly a month, I can finally at home - I came back.    As for not moving online, this should have been finished long ago article can only delay so long to "release." 

  In this chapter, I talk about how to use layout, as well as some other on the use of EditPolicy and Palette realized.    Elaborate, sample code and the code in the content of this chapter variance, it is because before I do a bit of writing that this more than I completed, but due to some technical differences, so I will be divided into two articles finish , I suggest that you read Chapter 5 of the code later.    Download the code. 

  1. Re show TableFigure 

  The previous chapter, we simply draw a rectangle, as our graphics database table, now let us re-think how to display this TableFigure. 

  Let us see how Visio is displayed inside the bar: 

  We also like to do it in accordance with a similar! 

  First, we need to show our table, and secondly, we have to field data in the table shows that the decentralization in the region, and then stored in the database table and field regional draw a line between, separated.    See next plans: 

  We seem to have previously written TableFigure far worse, just a rectangle that is not enough. 

  First consider how to display table.    TableFigure displayed in a text very easy, simple way is to draw it in time, the use of Graphics drawText method can be, but doing so is very cumbersome and need to keep the calculation table display position, and, when we table The name change, the size of the table itself to regulate it.    Therefore, we need to use Label to show, because Label can be easily displayed on the table for maintenance, including access to the length of text with the size of the Figure; In addition, when we use the Label to show, TableFigure can also layout manager to calculate their current size, and save our own calculated.    TableFigure open category, add the following code: 

  Public? TableFigure (Table? Model)? ( 
  ???????? Super (); 
  ???????? This. Model? =? Model; 

  ???????? TableNameLabel? =? New? Label (); 
  ???????? TableNameLabel.setText (model.getTableName ()); 
  ???????? FontData? Fd? =? New? FontData (); 

  ???????? Fd.setHeight (10); 
  ???????? Fd.setName ( "Arial"); 
  ???????? Fd.setStyle (SWT.BOLD); 

  ???????? TableNameLabel.setFont (new? Font (null, the fd)); 
  ???????? TableNameLabel.setIcon (ImageProvider.TABLE_ICON.createImage ()); 
  ???????? TableNameLabel.setLabelAlignment (PositionConstants.MIDDLE); 

  ???????? / /? Left point margins, points will be nice 
  ???????? This. SetBorder (new? MarginBorder (8, eight, eight, eight)); 

  ???????? This. Add (tableNameLabel); 
????????
  ???????? This. SetOpaque (true); 
????}

  We TableFigure created, it generated to a Label, and then this sub-Label as TableFigure Figure add to its top, and we have to let this one Label to display data table.    Code used in the above picture settings and font settings, here we only discuss GEF, it is not discussed them. 

  Names can show, let us now the containers out of the field! 

  Field graphics need to protect the containers that it, we just have seen, Visio in the field are in the field from top to bottom in an orderly containers are together, to the problem: how to get they are so obedient to be orderly.    Layout Manager (LayoutManager), as did the desktop applications are aware that, yes, Draw2D also use layout manager to a position on the size of graphics maintain.    In Draw2D ToolbarLayout called in a layout manager, it has to Figure orderly arranged with the top down, this is exactly what we need! 

  Let us now in TableFigure constructor function to add the following code: 

  None containerFigure? =? New? Figure ()?; 

  ???????? ToolbarLayout? TableLayout? =? New? ToolbarLayout (); 
  ? 
  ???????? / /? Bearing Column? Figure containers is ToolbarLayout 
  ???????? ToolbarLayout? ContainerLayout? =? New? ToolbarLayout (); 
  ???????? ContainerLayout.setMinorAlignment (ToolbarLayout.ALIGN_BOTTOMRIGHT); 
  ???????? ContainerFigure.setLayoutManager (containerLayout); 
?????
  ???????? This. Add (containerFigure); 

  — So that our containerFigure on ahead. 

  But this is not enough light.    ContainerFigure and tableNamelable two of the Figure as TableFigure graphics, should be shown here?    How to position them?    Moreover, when our two graphics subsystems size change in the future, TableFigure how do? 
  In fact, all the problems are all from the layout manager to answer. 

  Figure in the category, there is a reputation getPreferredSize method, this method is to get the current size of the Figure.    Default circumstances, getPreferredSize method will check whether the Figure registered a layout manager, and if so, it will call for layout management getPreferredSize obtained size.    The layout manager getPreferredSize method is not simply to see the current Size Figure, but to the adoption of the layout of its own characteristics, and through the Figure in the location and size of graphics, according to a certain stack algorithm and the size of the current Figure . 

  To put it simply, if we use the ToolbarLayout, then when we call a registration of the Figure of the LayoutManager getPreferredSize methods, the layout manager will Figure set to the height of all of its height and Figure; width of all sub-Figure Set in the maximum width. 

  In this way, we have just under the painting of the graphics, and containerFigure tableNameFigure is the top-ranked of all, we can use ToolbarLayout TableFigure, layout manager to manage its size.    We wrote here read out, we set up ToolbarLayout containerFigure, but also to increase the field when we graphical time for layout manager to control its size. 

  We have basically completed TableFigure.    However, if we add in the database field, EditPart do not know to the field as TableFigure Figure is a subset of containerFigure graphics and added to it, and it is the default field TableFigure graphics directly to the drawing, so that we just the idea of a completely fail to realize.    Therefore, let us duplicate the getContentPane TableEditPart: 

  ? Public? IFigure? GetContentPane ()? ( 
  ???????? Return ((TableFigure) getFigure ()). GetContainerFigure (); 
????}

  What does this mean? 
  In the previous chapter I feel like I said, the GEF in a certain EditPart for its sub-EditPart graphics rendering is in the graphics on the EditPart - a recursive process.    But it is not EditPart graphics directly to the default of Fiuger Figure containers, but through methods to obtain getContentPane bearer of the Figure EditPart graphics, of course, the direct successor to GraphicalEditPart If so, the return of getContentPane directly getFigure is, therefore, when we To redefine containers Figure EditPart time, it is necessary to duplicate getContentPane. 

  2. Show ColumnFigure 

  Now we are to achieve graphics field. 
  Graphics field is as simple as a realization of field names and field can be said of the icon, so we will it inherited from the Label: 

  Public? Class? ColumnFigure? Extends? Label? ( 
  ?? Private? Column? Model; 
  ?? Private? Boolean? Selected; 
  ?? Private? Boolean? HasFocus; 
  None public? ColumnFigure (Column? Model) ( 
  ?????????? Super (); 
  ?????????? This. Model? =? Model; 
  ?????????? Model.setColumnName (model.getColumnName ()); 
??????????
  ?????????? FontData? Fd? =? New? FontData (); 
??????????
  ???????????? Fd.setHeight (8); 
  ???????????? Fd.setName ( "Arial"); 
  ???????????? Fd.setStyle (SWT.BOLD); 
  ?????????? This. SetIcon (ImageProvider.COLUMN_ICON.createImage ()); 
  ?????????? This. SetLabelAlignment (PositionConstants.LEFT); 
  ?????????? This. SetFont (new? Font (null, fd)); 
??????}
  ) 
  ColumnEditPart then let it return to the createFigure methods: 

  ?? Protected? IFigure? CreateFigure ()? ( 
  ????????//? TODO? Auto-generated? Method? Stub 
  ???????? Return? New? ColumnFigure ((Column) getModel ()); 
????}

  Ok, now let us amend the initializeGraphicalViewer DbEditor in: 

  Protected? Void? InitializeGraphicalViewer ()? ( 
  ????????//? Hard-coded to create a database model 
  ???????? Schema? Schema? =? New? Schema (); 
  ???????? Table? Table? =? New? Table (); 
  ???????? Table.setTableName (the "Test"); 
  ???????? Column? Column? =? New? Column (); 
  ???????? Column.setColumnName ( "test"); 
  ???????? Table.addChild (column); 
  ???????? Schema.addChild (table); 
  ???????? This.getGraphicalViewer (). SetContents (schema); 
????}
  OK, now we can see a new TableFigure the. 

  But there was a problem: the size of our own TableFigure not calculated, and even fields not displayed.    Surely some people say: is not to say that a layout manager can be a! 

  And so on, but also remember that the last chapter, we can move to rectangular, and the replication refreshVisuals method?    Now we are re-write it again: 

  ? Protected? Void? RefreshVisuals ()? ( 
  ???????? Super.refreshVisuals (); 
  ????????//? Be the size of the current TableFigure, due to the Toolbar layout constraints, it will automatically calculate 
???????
  ???????? Dimension? Size? =? This.getFigure (). GetPreferredSize (); 
????????
  ????????//? Access changes the location, position in the maintenance of the Model 
  ???????? Point? P ?=?(( Table)? GetModel ()). GetLocation (); 
????????
  ????????//? We only changes the location of Table 
  ????????(( GraphicalEditPart)? This.getParent ()). SetLayoutConstraint (this,? This 
  ????????????????. GetFigure (), new? Rectangle (p, the size)); 
????}

  Read the code before a friend discovered the different: the size is no longer simple to obtain the size of the current bounds, but through our above said, the methods used to get the layout getPreferredSize calculation! 

  Later revised look at our TableFigure: 

  Add a few words: size, I found I think it is important to say that a number of other details, such as maximum and minimum size TableFigure bound ah, how the painting tableNameLabel line ah, and ah Label stops, the use of border ah, Gradual rectangular drawing ah, I did not mention these, we can see their own code, if any doubt can post discussion. 

  3. Regenerate PaletteRoot 

  In our previous example, the tools generate panel is a very simple panel, above bare, not by the panel tools to increase our Viewer Figure graphics, every time we need to make in the replication DbEditor revised code, with a hard coding model to achieve the increase. 

  Now we have to construct a Table and Column can create the tools panel, hard-coded to create model hell, let them. 

  Mr. state into a single category: PaletteFactory, and then we generate inside an empty PaletteRoot, Zailong two PaletteDrawer add to PaletteRoot: 

  Public? Class? PaletteFactory? ( 
  ?? 
  ?? Private? PaletteRoot? Root; 
  ?? 
  ?? Private? PaletteDrawer? DefaultTools; 
  ?? 
  ?? Private? PaletteDrawer? DbTools; 
  ?? 
  ?? Private? Static? PaletteFactory? Instance? =? Null; 
  ?? Private? PaletteFactory () () 
  ?? 
  ?? Public? Static? PaletteFactory? INSTANCE () ( 
  ???????? If (instance? ==? Null)? Instance? =? New? PaletteFactory (); 
  ???????? Return? Instance; 
????}
  ?? 
  ?? Public? PaletteRoot? CreatePaletteRoot () ( 
  //???????? If (root? =? Null)? Return? Root; 
????????
  ???????? Root? =? New? PaletteRoot (); 
  ???????? Root.add (createDefaultToolBox ()); 
  ???????? Root.add (createDbToolBox ()); 
  ???????? Return? Root; 
????}
  ?? 
  ?? Private? PaletteDrawer? CreateDefaultToolBox () ( 
  ???????? DefaultTools? =? New? PaletteDrawer ( "Default? Tools"); 
????????
  ???????? DefaultTools.add (new? SelectionToolEntry ()); 
????????
  ???????? Return? DefaultTools; 
????}
  ?? 
  ?? Private? PaletteDrawer? CreateDbToolBox () ( 
  ???????? DbTools? =? New? PaletteDrawer ( "DataBase? Tools ");???????? 
  ???????? Return? DbTools; 
????}
  ) 

  I simply say something, PaletteDrawer is a container can be hidden, it can increase buttons above ToolEntry.    What is ToolEntry?    We can be understood as any in the Palette above elements: buttons, dividing line, containers, etc., there is a corresponding ToolEntry Tool, through the createTool ToolEntry return, if we need some special treatment, we can direct to realize ToolEntry and Tool, but In our example, what we need is the ToolEntry model can be generated, we would not have to study ToolEntry Tool and the working principle. 

  Then descend said. 
  The code, we have to increase defaultTools a SelectionToolEntry containers, it is provided by the GEF itself a tool for the graphical user click on the option, it is not the role of nonsense here:) 

  Below from the code can be seen, we have not increased the creation of the Column and Table ToolEntry, we are now to achieve them. 

  ToolEntry create two were named as TableToolEntry and ColumnToolEntry, they are inherited CreationToolEntry.    CreationToolEntry attention to the structure function, a need for imported CreationFactory, is the creation of this plant we have to return to the model example of the factory, and its two methods: getNewObject () and getObjectType () is returned to the creation of the model and model type. 

  We look at the realization of the factory: 

  Public? Class? DbCreationFactory? Implements? CreationFactory? ( 

  ?? Private? Class? Type; 
  ?? Public? DbCreationFactory (Class? Type) ( 
  ???????? SetType (type); 
????}

  ?? Public? Object? GetNewObject ()? ( 
  ???????? If (type? ==? Table.class) ( 
  ???????????? Return? New? Table (); 
????????}
  ???????? If (type? ==? Column.class)? Return? New? Column (); 
  ???????? Return? Null; 
????}

  ?? Public? Object? GetObjectType ()? ( 
  ????????//? TODO? Auto-generated? Method? Stub 
  ???????? Return? GetType (); 
????}
  ?? ……. 
  ) 
  By creating this type of plant into the parameters of the model can generate the corresponding 

  Let us look at our TableToolEntry ColumnToolEntry and the realization of: 

  Public? Class? TableToolEntry? Extends? CreationToolEntry? ( 
  ?? Public? TableToolEntry ()? ( 
  ???????? Super ( "Table", "Create? A? Table"? New? DbCreationFactory (Table.class)? ImageProvider.TABLE_ICON, the null); 
????}
  ) 

  Public? Class? ColumnToolEntry? Extends? CreationToolEntry? ( 
  ?? Public? ColumnToolEntry () ( 
  ???????? Super ( "Column", "Create? A? Column"? New? DbCreationFactory (Column.class)? ImageProvider.COLUMN_ICON, the null); 
????}
  ) </ Span> 
  All seen, and we are all imported counterparts DbCreationFactory their need to be generated model parameters. 

  Now, we create the category ToolEntry Well, let us add to the PaletteDrawer dbTools: 

  Laws? PaletteFactory category createDbToolBox () method 

  ?? Private? PaletteDrawer? CreateDbToolBox () ( 
  ???????? DbTools? =? New? PaletteDrawer ( "DataBase? Tools"); 
????????
  ???????? DbTools.add (new? TableToolEntry ()); 
  ????????? DbTools.add (new ColumnToolEntry ()); 
?????
  ???????? Return? DbTools; 
????}

  Operation to: 

  4. New Command; FlowEditPolicy usage 

  Completion of the above work, we isolated from the instrument panel to create model also almost: EditPolicy no corresponding Command. 

  Previous chapters, as we all know, the GEF All of the incidents in the package sent out a Request, and then find EditPolicy with EditPolicy go from Command to implement.    We have been generated in the previous chapter on a TableMoveCommand Therefore, I believe we should not unfamiliar to the Command. 

  We generate such a Command: DbItemCreationCommand 

  Public? Class? DbItemCreateCommand? Extends? Command? ( 
  ?? Private? DBBase? Parent; 
  ?? Private? DBBase? Child; 
  ?? Private? Int? Index? =? 1; 
  ?? 
  ?? Public? Void? Execute ()? ( 
  ???????? Assert.isNotNull (parent); 
  ???????? Assert.isNotNull (child); 
  ???????? Parent.addChild (index, child); 
????}

  ?? Public? Void? Redo ()? ( 
  ???????? Execute (); 
????}

  ?? Public? Void? Undo ()? ( 
  ???????? Assert.isNotNull (parent); 
  ???????? Assert.isNotNull (child); 
  ???????? Parent.removeChild (child); 
????}
……
??……
  ) 
  Now, with the Command, we will have to consider it, look at it say to whom the EditPolicy to return. 

  Under normal circumstances, if we want to generate a model, then we should be in the containers EditPolicy father registered a Command, because the majority of the types of containers EditPart have installed ContainerEditPolicy or LayoutEditPolicy, which can be precisely two EditPolicy CreateRequest on the capture and processing.    Therefore, with our example, it is necessary to generate Table model, it would be in his father EditPart - SchemaEditPart in the SchemaLayoutEditPolicy make a fuss about. 

  Opened this category, and discovered that they have a way: getCreateCommand, we will return here in DbItemCreateCommand bar: 

  Protected? Command? GetCreateCommand (CreateRequest? Request)? ( 
  ???????? Object? Obj? =? Request.getNewObject (); 
  ???????? If (obj? =? Null? &? Request.getNewObjectType ()?==? Table.class) ( 
  ???????????? DbItemCreateCommand? Command? =? New? DbItemCreateCommand (); 
  ???????????? Command.setParent ((DBBase) this.getHost (). GetModel ()); 
  ???????????? Command.setChild ((DBBase) obj); 
  ????????????(( Table) obj). SetLocation (request.getLocation ()); 
  ???????????? Return? Command; 
????????}
  ???????? Return? Null; 
????}
  See above code found?    We must CreateRequest carrying an object and the type of examples, and even when we click in the creation of the position in the Viewer also Therefore, we only need to set some DbItemCreateCommand father model and the model can, of course, we also need to in the generation model, the model will be generated by the mouse click position to Table model, so that he will be at the creation of a position.    Too cool! 

  But just add a model EditPart do not know, I need to refresh this notice EditPart.    Remember that the last chapter, rectangular position changes after notice is how EditPart?    I wordy about it: We use the model in the PropertyChangeSupport attribute issued notification of change, and then ran after it intercepted EditPart corresponding action can be: 

  Some code changes DBBase code: 

  Public? Void? AddChild (int? Index?, The DBBase? Child) ( 
  ???????? If (index ?==?- 1) ( 
  ???????? GetChildren (). Add (child); 
  ????????} Else ( 
  ???????????? GetChildren (). Add (index, child); 
????????}
  ???????? Child.setParent (this); 
  ???????? This.fireChildenChange (child); 
????}
  ?? 
  ?? Public? Void? RemoveChild (DBBase? Child) ( 
  ???????? Child.setParent (null); 
  ???????? GetChildren (). Remove (child); 
  ???????? This.fireChildenChange (child); 
????}

  ?? Public? Void? FireChildenChange (DBBase? Child) ( 
  ???????? Support.firePropertyChange (PRO_CHILD, null, child); 
????}

  Let DBEditPartBase to intercepted PRO_CHILD events: 

  ? Public? Void? PropertyChange (PropertyChangeEvent? Evt)? ( 
  ??????? String? PName? =? Evt.getPropertyName (); 

  ??????? If (pName.equals (DBBase.PRO_CHILD)) ( 
  ??????????? This.refreshChildren (); 
  ??????????? This.refreshVisuals (); 
???????}
????}
  Finally, let us DbEditor in the previous generation model in the code removed, let's Content Viewer Schema can be set to one, 
  Well, running a bar, is not to create Table?  :)

  5.FlowLayoutEditPolicy applications and the creation of Column 

  We have to create Table, and now need to create a Column. 

  In the above we have created a model of the formation conditions Column: ColumnToolEntry, DbCreateFactory also DbItemCreateCommand Helper same: we put this Command to where? 

  Past experience tells us that this is the need to ColumnEditPart Command of the EditPolicy EditPart father to return, but its EditPart father, but also on TableEditPart, there has been installed to protect the EditPolicy creation model, we need to create an installation he on. 

  We use a class called FlowLayoutEditPolicy as our new EditPolicy Father category, it is because a specific FlowLayoutEditPolicy ToolbarLayout FlowLayout layout manager and the Figure and done, it can be the location of mobile pairs Figure make some maintenance, such as when We TableFigure drag in the ColumnFigure, FlowLayoutEditPolicy can be inserted into the location a black line: 

  We named this category on TableFlowLayoutEditPolicy: 

  Public? Class? TableFlowLayoutEditPolicy? Extends? FlowLayoutEditPolicy? ( 

…….
?
  ?? Protected? Command? GetCreateCommand (CreateRequest? Request)? ( 
  ???????? Object? Obj? =? Request.getNewObject (); 
  ???????? If (obj? =? Null? &? Request.getNewObjectType ()?==? Column.class) ( 
  ???????????? DbItemCreateCommand? Command? =? New? DbItemCreateCommand (); 
  ???????????? Command.setParent ((DBBase) this.getHost (). GetModel ()); 
  ???????????? Command.setChild ((DBBase) obj); 
????????????
  ???????????? EditPart? After? =? GetInsertionReference (request); 
  ???????????? Int? Index? =? GetHost (). GetChildren (). IndexOf (after); 
  ???????????? Command.setIndex (index); 
  ???????????? Return? Command; 
????????}
  ???????? Return? Null; 
????}
  ? ……. 
?…………
  ?? Protected? Boolean? IsHorizontal ()? ( 
  ???????? IFigure? Figure ?=?(( GraphicalEditPart) getHost ()). GetContentPane (); 
  ???????? LayoutManager? Layout? =? Figure.getLayoutManager (); 
  ???????? If (layout? Instanceof? FlowLayout) 
  ???????? Return ((FlowLayout) figure.getLayoutManager ()). IsHorizontal (); 
  ???????? If (layout? Instanceof? ToolbarLayout) 
  ???????????? Return ((ToolbarLayout) figure.getLayoutManager ()). IsHorizontal (); 
  ???????? Return? False; 
????}
  ) 

  We returned to the getCreateCommand in DbItemCreateCommand, parent Set Table, which is generated child with the request Column, because Column is no concept of the position, we do not have to place parameters to it (no variable to the preservation ah) it is only in this table may be the first of several it, and we are also mentioned in the above, in the mobile ColumnFigure time FlowLayoutEditPolicy can draw a black line that the current location of the inserted, we passed and then we approach the current getInsertionReference black lines of the corresponding index EditPart, and then get in the EditPart EditPart TableEditPart subset of the location,再传handed Command, let us new generation of EditPart add to the position. 

  However, let FlowLayoutEditPolicy showed black lines, we also need to duplicate it? IsHorizontal, because by default, FlowLayoutEidtPolicy? IsHorizontal method at run time that the installation of the EditPolicy EditPart use the FlowLayout, but we use here ToolbarLayout is, if we do not duplicate the case, the switch will be thrown type anomaly. 

  We simply can be modified to the conduct of, or directly had he returned to the true:) 

  As we have already ColumnEditPart Column, as well as the base class has been added after the addition of nodes attribute code changes, it would not have written here. 

  Now we can click on the toolbar of the column in the Table tool in the creation of the Column. 

  Let us look at the overall results: 

  6. CONCLUSION 

  This time, we have basically resolved the database tables and fields of the realization of the database, the next chapter then goes on to talk we will, in fact there has been a code, interested friends can see. 

  The next chapter I will talk about how to achieve in the GEF PropertyPage applications, as well as some of the problems Connection 

  Posted on 2006-10-09 19:02 Dart reading (692) Comments (5) edit their collections quoted Category: GEF 

Linux explain shutdown order

  Linux explain shutdown order 

  Posted on 2006-12-15 18:25 Yi Yi read again (19) Comments (0) edit their collections quoted Category: resources / gossip 

My life planning

  My life is always planning Xiebukuan this article, because things change, I will not write too far, the plan only because life generally, there can be no concrete. 



  To their suggestions: 

  1.    Down-to-earth. 

  2.    One, credibility. 

  3.    Capable. 



  These three points, I think I can do it, I will succeed. 



  For 1. Down-to-earth. 

  I believe that the most pragmatic basis is the basis of success.    Because I have not heard of vacant buildings, but also have not heard the cornerstone of shallow high-rise buildings can be propped up.    Therefore, to move steadily, step by step, down a solid foundation for their own well is the premise of the premise. 

  For 2.    One, credibility. 

  Loyalty, not only to parents, including the BOSS now.    Loyalty, this is a fine tradition, loyalty is a character in the tests, but certainly not the stereotypical loyalty, loyalty to the parents, so that the sons and daughters of the elderly are in Kenfang Here; treat their own boss and benefactor, should act according to their conscience.    Filial piety to their parents.    My parents hygiene is not easy, not easy to support me even more, which is really the conscience of children are unfilial?    I dare say that my life has always been for my own life, because my parents is part of life, I live, and they like!    ! 

  Honesty, regardless of who is for and what time do not forget!    Life in the world, be an indomitable spirit, remember:: integrity-based. 

  For 3.    Capable. 

 ä¸èƒ½è‡ªå·±ink do not have to know the skills of this is the only Health. 





  My sentiment on that simple.    Syrian question.    Posted on 2005-11-15 11:10 karlzou reading (203) Comments (0) quoted edit collections for the category: the beginning 

And the thread pool thread on the basic knowledge

  ?? Thread is a major characteristic of Java, it can be given the instruction sequences, the method given in the definition of variables or some sharing of data (a type of variable).    Each thread in Java have their own stack and the program counter (PC), which is used to track thread stack in the context of (the context is that when the implementation of the thread somewhere, the current value of local variables), and procedures Counters are used to track the current thread is the implementation of the directive. 

  î—¥ î—¥ under normal circumstances, a thread can not visit another thread stack variables, and the threads must be in a state of the following: 

  î—¥ î—¥ 1. Queue status (Ready), the user creates a thread, the thread that will run immediately.    When the method of thread start () is called, the thread will be a state of the queue, waiting for the scheduling procedures will be running into it (Running).    When a process is executed after it can be queuing state.    If scheduling procedures permitting, by calling the methods yield () would be in the process Add to queue status. 

  î—¥ î—¥ 2. Running (Running), when scheduling procedures CPU running time allocated to a thread, the thread entered the running started operation. 

  î—¥ î—¥ 3. Wait for the state (Waiting), many reasons can lead to threads in a wait state, such as in the implementation of the thread was suspended, or wait for the I / O requests into waiting for the completion of the state. 

  î—¥ î—¥ in Java different threads with different priorities, high-priority threads can be arranged in low-priority threads to complete.    If multiple threads have the same priority, Java will switch between different threads running.    An application can be threaded through the use of the method setPriority () to set the thread priority, using getPriority () to obtain the priority of a thread. 

  î—¥ î—¥ threads of the life cycle 

  î—¥ î—¥ a thread of the life cycle can be divided into two phases: survival (Alive) cycle and death (Dead) cycle, which also include life-cycle operation of state (Running), and wait for the state (Waiting).    When creating a new thread, the thread queuing to enter the state (Ready), when the method of thread start () is called, the thread into the life-cycle, when it means isAlive () always return true value until the thread into the death of state. 

  î—¥ î—¥ the realization of thread 

  î—¥ î—¥ There are two ways to achieve thread, and the other is to expand java.lang.Thread class, and the other is through the java.lang.Runnable interface. 

  î—¥ î—¥ Thread class encapsulates thread acts.    To create a thread, we must create a category expanded from Thread of new categories.    As the Thread class methods run () does not provide any operation, therefore, in the creation of threads, users must cover methods run () to complete useful work.    When the method of thread start () is called, and methods run () to be called.    The following code is through expansion to achieve thread Thread type: 

  Import java.awt .*; 
  (Class Sample1 
  Public static void main (String [] args) ( 
  ? Mythread test1 = new Mythread (1); 
  ? Mythread test2 = new Mythread (2); 
  ? Test1.start (); 
  ? Test2.start (); 
  ) 
  ) 
  Class Mythread? Extends Thread ( 
  Int id; 
  Mythread (int i) 
  (Id = i;) 
  Public void run () ( 
  ? Int i = 0; 
  ? While (id + i == 1) ( 
  ? Try (sleep (1000); 
  ?) Catch (InterruptedException e) () 
  ) 
  System.out.println ( "The id? Is" + id); 
  ) 

  î—¥ î—¥ usually when the user wants a class will be able to run in their own thread, but also extended certain other categories of characteristics, it is necessary to run through the Runnable interface to achieve.    Runnable interface method only one run ().    No matter what the time created a use of the Runnable interface type, must be prepared in the class run () method in the interface to cover the run () method.    For example, the following code is through Runnable interface thread: 

  Import java.awt .*; 
  Import java.applet.Applet; 
  Public class Bounce extends Applet implements Runnable ( 
  Static int r = 30; 
  Static int x = 100; 
  Static int y = 30; 
  Thread t;? 
  Public void init () 
  ( 
  ? T = new Thread (this); 
  ? T.start (); 
  ) 
  Public void run () 
  ( 
  ? Int y1 = +1;? 
  ? Int i = 1; 
  ? Int sleeptime = 10; 
  ? While (true) 
  ? ( 
  ? Y + = (i * y );???? 
  ? If (yr <i ||y+r> getSize (). Height )????????????? 
  ? Y1 *=- 1; 
  ? Try ( 
  ? T.sleep (sleeptime); 
  ?) Catch (InterruptedException e) () 
  ?) 
  ) 
  ) 

  î—¥ î—¥ Why you should use a thread pool 

  î—¥ î—¥ in Java, if every time a request arrived on the creation of a new thread, the cost is considerable.    In actual use, every request to create a new thread in the server thread creation and destruction, and time spent on the consumption of system resources, and may even than to dealing with the actual users of the request is much more time and resources.    In addition to creating and destroying threads overhead, the thread also need to consume system resources.    If a JVM in the creation of too many threads, may lead to excessive consumption due to system memory or "switch over" and lead to lack of system resources.    In order to prevent the lack of resources, application servers need some way to limit any given moment with the number of requests, minimize the creation and destruction of the number of threads, in particular some of the resources spent relatively large thread creation and destruction, to make full use of has been targeted for this service is the "pool of resources" from technical reasons. 

  î—¥ î—¥ main thread pool thread to solve the problem life cycle costs and inadequate resources issues.    Through the multiple tasks reusable threads, thread creation costs to be assessed on a number of tasks, but also due to the arrival of threads in the request already exists, so the threads created by the elimination of the delay.    Therefore, we can immediately request services to enable faster application response.    In addition, through the appropriate adjustments to the number of thread pool thread can prevent the shortage of resources. 

  î—¥ î—¥ create a thread pool 

  î—¥ î—¥ a relatively simple thread pool shall contain at least the thread pool management, thread work, job queue, the task of the interface.    One thread pool management (ThreadPool Manager) is the role of creation, destruction and manage the thread pool will work Add thread pool thread; work can be recycled is a thread implementation of the mandate of threads, in the absence of mandate to wait; job queue role is to provide a buffer mechanism would not deal with the tasks on the job queue; task interface is the need for each task interface, the main entrance to the mandate, the mandate after The relevant work, such as implementation of the mandate of the state, the thread through the implementation of the mandate of scheduling interface.    The following code to achieve the creation of a thread pool, as well as removed from the thread pool thread operation: 

  Public class ThreadPool 
  (? 
  Private Stack threadpool = new Stack (); 
  Private int poolSize; 
  Private int currSize = 0; 
  Public void setSize (int n) 
  ( 
  ? PoolSize = n; 
  ) 
  Public void run () 
  ( 
  ? For (int i = 0; i <poolSize; i + +) 
  ? ( 
  ? WorkThread workthread = new WorkThread (); 
  ? Threadpool.push (workthread); 
  ? CurrSize + +; 
  ?) 
  ) 
  Public? Synchronized WorkThread? Getworker () 
  ( 
  ? If (threadpool.empty ()) 
  ? System.out.println ( "stack is empty"); 
  ? Else 
  ? Try (return threadpool.pop (); 
  ?) Catch (EmptyStackException e) () 
  ) 
  ) 

  î—¥ î—¥ thread pool for application of occasions 

  î—¥ î—¥ when a Web server received a large number of requests for short-thread, the use of the thread pool is a very appropriate technology, which can greatly reduce the creation and destruction of thread number, improve server efficiency.    But if the requirements of the threads running relatively long time, then the thread running time is much longer than the time to create, to reduce creation time alone on the efficiency of the system not obvious, is not suitable for this application thread pool technology, the need With other technologies to improve the efficiency of services server.    Published in 2007-01-31 10:29 stme reading (538) Comments (0) edit their collections quoted Category: Algorithm 

J2EE start exploring

  J2EE start exploring 

  All along, the understanding of J2EE are intermittent, but it has become more and more like thick, the majority of the time on top of this, certainly, they will encounter many difficulties, we want to help; also have some experience might be useful to share with you. 

  Posted on 2007-04-02 14:02 debut reading (65) Comments (0) edit collections cited 

NetBean 5.5 UI language settings

  NetBeans 5.5 UI language settings now the default installation netbeans 5.5 UI for the Chinese language, and if necessary to amend the Chinese, just netbeans install directory for the appropriate settings to: 
  1. Go to $ netbeans / etc 
  2. Use a text editor to open netbeans.conf. 
  3. "Netbeans_default_options" added after the item "- locale language = en." 
  4. Restart netbeans e can see the text of the UI netbeans 
  More windows xp installed in the test passed, in the next linux similar settings.    Posted on 2007-07-15 15:17 snow Guhong reading (26) Comments (0) edit their collections quoted Category: Tools 

Rome read through the feed and found that some Chinese gibberish. .

  Rome read through the feed and found that some Chinese gibberish.    . 

  ?? Spent the jar rome 0,8 packages, most of the code samples from rome–0.7. 
  Right, and the release of rome links Rome's Home can be downloaded directly.    Rome there is the use of the information to the xml document output 

  , Part of a hash do not know how the case is    , I read the paper feed is utf-8, I read through the utf8    , But there is still part of hash.    Today, for one day have not been solved.    .    . 

UC

  UC 43828348 

  Http://www.wsmmz.net 

  Http://www.sooweb.net/Html/Soft/82.html 

  Http://www.hnwuyun.com/jc/ 

  Http://club.cat898.com/newbbs/printpage.asp?BoardID=18&ID=760319 

  Http://lsdw.go1.icpcn.com/pstg/6.htm 

  Http://font.flash8.net/font/list.aspx?page=3&c_id=383&s_id=395 posted on 2006-02-02 11:17 read my java (32) Comments (0) edit collections cited 

keep looking »