Re: DocumentListener is too slow



> I take it the performance problem is with each key press, not set up time.

Correct, each char that get's modified does a lookup on the correct
Hashtable, to get another Hashtabel for that type, makes the change,
and put's it back in.

> >
> > public void changedUpdate( DocumentEvent de ) {
>
> This event is called when a attribute (for instance colour) is changed.
> I think it's insertUpdate and removeUpdate you really want.

What I really have is a method that insertUpdate(), removeUpdate(), and
changedUpdate() all call a single method that does the same, so no
matter what the user does to the textfield, it updates my stored data.

>
> > Document doc = de.getDocument();
> >
> > // Since this listener is registered to a material form,
> > // I get the current material definition from FormDefinitions
> > // which is a static Hashtable of form types
> >
> > int matId = FormDefinitions.getInstance().getCurrentMaterial();
> > Material material = (Material)
> > FormDefinitions.getInstance().get(MATERIAL_FORM, matId);
>
> Ick. Singleton abuse.

I know, I hated doing this too, but I didn't know how else to do it. I
didn't want to have a "god" class init everything or pass this stored
data around in every method that needed it (which was a lot), cause the
code was really looking ugly. So I figured as long as I didn't have to
many of these around, it'd be ok. Certainly works better, but if I only
had a better way ... cause I use this data all over my application.


>
> > // get user typed input
> > String txt = doc.getText(0, doc.getLength());
> >
> > // set info to my material object
> > if (label.getText().equals("weight")) {
>
> That is really nasty.

Agreed, but how else do I know which field was updated and map it to my
storage classes?

>
> > material.setWeight(new Integer(txt));
> Glad to see someone is going for a half decent UI.
>
> If you are trying to store it back to a database I would suggest you:
> o Execute the updates in another thread.
> o Group all remaining outstanding updates each transaction.
> o Have some sort of minimum period between transactions.
> o If multiuser, cache in a middle tier.

Actually, no database, just POJO's stored in memory.

.



Relevant Pages

  • Re: Recordset.AddNew and the recordset objects data retaining
    ... The statement you make about the individual updates not hitting the database ... to do with the updates being in a transaction but rather on whether you specify ... spill over and the memory starts paging out to disk that concerns me). ...
    (microsoft.public.data.ado)
  • Re: Transaction with stored procedure
    ... You could try using linked servers/remote servers to do the updates from one ... I started a transaction against the one database. ...
    (microsoft.public.dotnet.languages.vb)
  • Code works without Transaction, but not with
    ... With the transaction statements back ... updates do not work. ... the back end, so I created a new back end database, imported the table ... corruption problem, but the transaction still does not work. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Inserts and updated sqlserver
    ... > has its own session to the database. ... > If I do all the inserts and do updates in one thread it works fine. ... the end of it and the transaction is rolled back after the timeout. ...
    (microsoft.public.sqlserver.server)
  • RE: Master/Detail Transactions
    ... If any of the updates fails, ... pending parent and child rows within the scope of a transaction, ... cascade newly retrieved parent identity values down to pending child rows ...
    (microsoft.public.dotnet.framework.adonet)