You're doing it wrong ...

Status
Not open for further replies.
Code:
class SafeStringBuffer extends StringBuffer {

  public StringBuffer append(String s) {
    if (length() + s.length() > 32 * 1024) {
      System.out.println("Too big.");
      System.gc(); // if too big, GC to reduce memory usage
    }
    else {
      try {
        super.append(s);
      } catch (Exception e) {
        // extra safe, just in case the check above wasn't enough
        e.printStackTrace();
      }
    }
  }

  protected void finalize() {
    // stop memory leaks
    super.delete(0, length());
    super.delete(0, length()); // try again just to be sure
    System.gc();
  }
}

You're welcome. :)
 
741":i8odoilt said:
newwb":i8odoilt said:
Code:
    super.delete(0, length());
    super.delete(0, length()); // try again just to be sure

I don't know any Java, but I'm curious: what is the point of calling this twice? Is it considered proper coding style?

I remember when learning UNIX (Solaris to be exact) back in the Solaris 2.3 days ...

Code:
sync; sync; sync; init -6

This was the only safe way to reboot. If you didn't sync at least three times before you rebooted, you'd have corruption issues -- or so the trainers/instructors told us. I think it was simply dogma.
 
newwb":14j50v1q said:
Code:
class SafeStringBuffer extends StringBuffer {

  public StringBuffer append(String s) {
    if (length() + s.length() > 32 * 1024) {
      System.out.println("Too big.");
      System.gc(); // if too big, GC to reduce memory usage
    }
    else {
      try {
        super.append(s);
      } catch (Exception e) {
        // extra safe, just in case the check above wasn't enough
        e.printStackTrace();
      }
    }
  }

  protected void finalize() {
    // stop memory leaks
    super.delete(0, length());
    super.delete(0, length()); // try again just to be sure
    System.gc();
  }
}

You're welcome. :)

:stab: but that's not enterprisy enough -- you need to invoker a Logger and output the 'too big' as an XML-formatted output ...
 

fitten

Ars Legatus Legionis
55,636
Subscriptor++
zelmak":37c08nea said:
I remember when learning UNIX (Solaris to be exact) back in the Solaris 2.3 days ...

Code:
sync; sync; sync; init -6

This was the only safe way to reboot. If you didn't sync at least three times before you rebooted, you'd have corruption issues -- or so the trainers/instructors told us. I think it was simply dogma.

We always did (depending on flavor): sync; sync; reboot

I don't think you had to do that with Solaris but it was an issue with SunOS and probably just carried over to Solaris as dogma. (I always sync; sync; reboot on Solaris, too)
 

OmniWrench

Ars Scholae Palatinae
1,427
zelmak":3dvlnpgp said:
newwb":3dvlnpgp said:
Code:
class SafeStringBuffer extends StringBuffer {

...infuriating Java code...
}

You're welcome. :)

:stab: but that's not enterprisy enough -- you need to invoker a Logger and output the 'too big' as an XML-formatted output ...

... then log the same string in the calling function so that it shows up more than once in the logs.
 

ronelson

Ars Legatus Legionis
21,399
Subscriptor
This was the only safe way to reboot. If you didn't sync at least three times before you rebooted, you'd have corruption issues -- or so the trainers/instructors told us. I think it was simply dogma.
I think on really poorly written software, and some versions of the OS, it could cause failures as apps shut down and before cached FS information was written out (think: something checks disk utilization to look for free space before writing a large log file that will fill the partition, but suddenly the sync forces a large amount of unwritten data to plop down first and now the log file craps out. Depending on how your OS handled that, it could write over the sectors on the disk where that unwritten data went). But not after '85 or so, then it was just a joke.

Now, if you played around with your RAID caching mechanism too much, you could type "sync" and have to wait 10 seconds to get a prompt back. In cases like that, I would type sync first just to watch it churn :)
 
in other news:

Code:
Map fields = new HashMap();  // note: code origins circa 2000 so no generics in-use
.
.
.
Calendar calHolder = Calendar.getInstance();  // generic Calendar? new Date() creates a much easier-to-use 'now'
                                              // but if you must use Calendar, then GregorianCalender is more appropriate
// spurious boxing when unneeded 'new String' is just wrong 
// ... and ... really? Hasn't SimpleDateFormat been around since then?
String strCurrentTime = new String( new Integer(calHolder.get(Calendar.YEAR)).toString() +
                                    new Integer(calHolder.get(Calendar.MONTH)+1).toString() +
                                    new Integer(calHolder.get(Calendar.DATE)).toString() +
                                    new Integer(calHolder.get(Calendar.HOUR)).toString() + 
                                    new Integer(calHolder.get(Calendar.MINUTE)).toString() +
                                    new Integer(calHolder.get(Calendar.SECOND)).toString() );
// field name is a literal instead of captured in a static final String or a map or list of field names?
fields.put("Time Processed", strCurrentTime);
:twitch:

Sadly, this isn't even captured in a local library but copy-pasta'd throughout (at least) 38 source files. Some other classes use similar, but not exact formatting and variable names, but the code is essentially the same.
 
jxl":1jfu2smy said:
Who's responsible for the passive-aggressive commenting there?
If there's this much copypasta about, perhaps use PMD or something?

Wish I could. I'm contract maintenance/enhancement ... refactoring/redesign is hard to get pushed through ... I sneak in a refactoring here and there based on the focus of the current 'ticket' but it is hard as the system is so tightly coupled that a change from ArrayList to List<String> in a parameter ripples outward like a space capsule splashing into a calm pond.

As well as (1) we're on a private, non-internet connected network, (2) software must be certified before being put on this network and (3) OSS is OMG scary 'cuz it could phone-home ...

Yes, the privacy of the network makes sense, but ... yeah, I don't fully understand the paranoia either ... it is really a bitch to get patches to -- or upgrades which patch -- known vulnerabilities installed due to these wacky policies.
 
zelmak":3jk0b26c said:
Code:
sync; sync; sync; init -6

This was the only safe way to reboot. If you didn't sync at least three times before you rebooted, you'd have corruption issues -- or so the trainers/instructors told us. I think it was simply dogma.
The first sync did the trick but in days gone by disk systems were slow enough that you had to wait a bit before issueing the reboot. The other 2 syncs were just time spacers.
 

Centine

Ars Scholae Palatinae
1,019
Subscriptor
rrrhal":31azc7qs said:
zelmak":31azc7qs said:
Code:
sync; sync; sync; init -6

This was the only safe way to reboot. If you didn't sync at least three times before you rebooted, you'd have corruption issues -- or so the trainers/instructors told us. I think it was simply dogma.
The first sync did the trick but in days gone by disk systems were slow enough that you had to wait a bit before issueing the reboot. The other 2 syncs were just time spacers.
That sounds weird - I don't know SunOS at all though, but wouldn't applications keep doing I/O if you didn't shut down them down beforehand? So the first sync would probably flush upwards of 99% of all possible data in flight, but there's no actual guarantee that nothing new would arrive. Doing 3 syncs in a row would not guarantee this either, just reduce the probability enough that it seemed safe to the admin?
 
Centine":2xud6grc said:
That sounds weird - I don't know SunOS at all though, but wouldn't applications keep doing I/O if you didn't shut down them down beforehand? So the first sync would probably flush upwards of 99% of all possible data in flight, but there's no actual guarantee that nothing new would arrive. Doing 3 syncs in a row would not guarantee this either, just reduce the probability enough that it seemed safe to the admin?


IIRC, you've basically 'pulled the plug' on everything else before that. The only thing 'running' should be the sync itself and your shell. You didn't want to -run- any new programs either, little things like 'sleep 5' would mean the disk might be distracted from the crucial sync to actually load 'sleep'.

But 'sync' is already loaded - we know, we just ran it. :D

That is: This is all holdover from the dark ages.
 
Status
Not open for further replies.