Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FateFree
Nov 14, 2003

Kilson posted:

Can't you just use .drainTo() on the queue? Just drain the queue to a new list, and it's atomic.

Well theres no drainTo function, but I'd rather not drain the queue because if the save fails I'll lose all the metrics in memory. With removeAll I'll empty them only if they successfully save to the db, otherwise they'll stick around for the next attempt.

Adbot
ADBOT LOVES YOU

Brain Candy
May 18, 2006

You can always put things back into the queue :ssh:

Use LinkedBlockingQueue to have drainTo. Use offer to add things.

edit: there were words about iterators, but you don't need to care

Brain Candy fucked around with this message at 04:40 on Aug 7, 2013

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Oooo I'd never seen that drainTo method, I knew it had to exist but I was barking up the wrong tree, I needed to look at the BlockingQueue interface and it's implementations.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

FateFree posted:

Well theres no drainTo function, but I'd rather not drain the queue because if the save fails I'll lose all the metrics in memory. With removeAll I'll empty them only if they successfully save to the db, otherwise they'll stick around for the next attempt.

If you run the save operation directly out of the queue, and something is added from another thread right before you clear it, you're going to lose items anyway. Drain it to a list, and just don't clear the list unless the things save properly to the db.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
I asked this in another thread but I figured I'd ask it here as well.

I had an interview today for a Junior Java Developer job. It went really well and I like the culture, size, etc. I'm just a little concerned with the technology they use. They're using some Java technology (EJB/JBoss/JSP) that others have told me is "outdated" and while it fits the product they make, this was a little disconcerting to hear. This will really be my "first" dev job, so I'm not sure what to make of it. How much is it going to impact my career by starting off working with these things that (I've been told) may soon die? Will the experience I get here still open me up to good jobs in the future?

Forgive me if this is a retarded question. I'm a complete newbie and this really is my first developer job. As far as Java goes I haven't done much beyond advanced algorithms courses which used no frameworks or anything outside Core.

baquerd
Jul 2, 2007

by FactsAreUseless
Java technology gets outdated on a yearly basis, but going to raw EJB and JSP is almost a decade behind the curve. It should still be somewhat relevant because all of the modern tech that you should be using is built off of the older stuff.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Yea I wouldn't worry to much about it if you like the company. The tech is dated but is the foundation for all the newer tech. A key thing about java Dev is being able to adapt to new poo poo all the time.

IMlemon
Dec 29, 2008
I'm having embarrassingly hard time getting my head around generics. Here's the code I want to write:

Java code:
  Gateway<Whatever> gateway = new InMemoryGateway<Whatever>();
  gateway.create(new Whatever(1));
  Whatever w = gateway.findById(1);

  ...

  public class BaseEntity {
    public long id;
    public BaseEntity(long id) {
      this.id = id;
    }

    public long getId() {
      return id;
    }
  }

  public class Whatever extends BaseEntity {
    whatever
  }
Heres the gateway interface

Java code:
public interface Gateway <T extends BaseEntity> {
  public void create(T e);
  public T findById(long id);
}
And here's the first implementation I tried to write:

Java code:
public class InMemoryGateway<T extends BaseEntity> implements Gateway {
  private Map<Long, T> entities = new HashMap<Long, T>();

  @Override
  public void create(T e) {
    entities.put(e.getId(), e); // compile error, does not override superclass method
  }
  @Override
  public T findById(long id) {
    return entities.containsKey(id) ? entities.get(id) : null;
  }
}
Some stumbling around later:

Java code:
  public void create(BaseEntity e) {
    entities.put(e.getId(), e); // entities map expects T, got BaseEntity
  }
}
At this point I'm very confused why implementing method does not accept the type parameter but needs the upper bound type instead. Also why I can't just stuff in BaseEntities into a map that takes things that extend BaseEntity. I ended up just casting e to T and it works fine but looks retarded and wrong.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

IMlemon posted:

I'm having embarrassingly hard time getting my head around generics. Here's the code I want to write:

Heres the gateway interface

Java code:
public interface Gateway <T extends BaseEntity> {
  public void create(T e);
  public T findById(long id);
}
And here's the first implementation I tried to write:

Java code:
public class InMemoryGateway<T extends BaseEntity> implements Gateway {
  private Map<Long, T> entities = new HashMap<Long, T>();

  @Override
  public void create(T e) {
    entities.put(e.getId(), e); // compile error, does not override superclass method
  }
  @Override
  public T findById(long id) {
    return entities.containsKey(id) ? entities.get(id) : null;
  }
}

I'm pretty sure you want your implementation to have
code:
... implements Gateway<T> {
So that the create method will properly override.

Max Facetime
Apr 18, 2009

Yes, the T in InMemoryGateway is a different T than the superclasses' T. I think the subclass could be changed to InMemoryGateway<T2 extends BaseEntity> (not as a fix, but to restore some sanity).

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.
So, simplified, you have

Java code:
class Cage<T extends Animal>  {
  private Map <String, T> map = new HashMap<String, T>();
  
  public void put(String name, T animal) {
    map.put(name, animal);
  }

  public T get(String name) {
    return map.get(name);
  }
}
And instantiate it:

Java code:
 
Cage<Tiger> tigerCage = new Cage<Tiger>();
Now, lets looks at how you use use it. When you're getting, you're correct, T is the upper bound. It's perfectly valid to say:

code:
Animal dumbBeast = tigerCage.get("Khan");
However, when you're putting, T is the lower bound. You can't have:

code:
Animal sparky = new Dog();
tigerCage.put("Sparky", sparky);
because then you have a Dog in the tigerCage, and furthermore, when you try to retrieve Sparky, you're trying to retrieve him as a Tiger. However, you can put a more specific kind of Tiger in the tiger cage; you just can't to expect to get it out as the same type.

code:
BengalTiger stripes = new BengalTiger();
tigerCage.put("Stripes", stripes);

BengalTiger whatsHisName = tigerCage.get("Stripes"); //Nope, the tigerCage advertises that it contains Tigers. You can't assume what kind of tiger.
Tiger tStripes = tigerCage.get("Stripes"); //Perfectly valid
Animal aStripes = tigerCage.get("Stripes"); //Also ok.

DholmbladRU
May 4, 2006
nevemrind

DholmbladRU fucked around with this message at 15:26 on Aug 9, 2013

baquerd
Jul 2, 2007

by FactsAreUseless
I think I'm getting the hang of "Classes" now. Any suggestions?

Java code:
package Class;

public class Class extends Exception {
    Class Class;

    Class Class(Class klass) throws Class {
        if (klass.getClass() != Class.class) {
            throw new Class();
        } else {
            return Class;
        }
    }

    Class() throws Class {
        Class = new Class();
    }
}

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Class<C extends Class>?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

baquerd posted:

I think I'm getting the hang of "Classes" now. Any suggestions?

Java code:
package Class;

public class Class extends Exception {
    Class Class;

    Class Class(Class klass) throws Class {
        if (klass.getClass() != Class.class) {
            throw new Class();
        } else {
            return Class;
        }
    }

    Class() throws Class {
        Class = new Class();
    }
}

:barf: did you mean to post that in the coding horrors thread? I'm getting dizy just looking at it

baquerd
Jul 2, 2007

by FactsAreUseless

carry on then posted:

Class<C extends Class>?

I like it. It compiles.

code:
package Class;

public class Class<Clas extends Class> {
    Class Class;

    Class<Class> Class(Class<Class> Class) {
        if (Class.getClass() != Class.class) {
            return Class.Class.Class.Class.Class.Class.Class;
        } else {
            return Class.Class;
        }
    }
}

Brain Candy
May 18, 2006

Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.

Sundowner
Apr 10, 2013

not even
jeff goldblum could save me from this nightmare
I just attended an induction for my new course today (Software development, an HNC in Scotland) and they told us that we'll primarily be learning/using Java and I'm coming to the course as a complete newbie. Curious if there are any absolutely necessary/worthwhile books or documents online I should be aware of? I'm sure my lecturers will fill us in come the start of the actual course but I want to get a headstart and try and not gently caress this course up seeing as I'm floating entirely on student loans now (our Gov't usually funds a few courses but I burnt that funding "finding my way").

Any advice in general for a newcomer learning via a college course would be great and if anyone has specifically had education in Scotland (the west for me) then I'd love to hear more about your HNC/D experience. If this isn't necessarily the right place to discuss that though, let me know where to post!

Sundowner fucked around with this message at 13:15 on Aug 15, 2013

DholmbladRU
May 4, 2006
I have created a web service in java using import javax.xml.ws.Endpoint;. However I am a little confused about how to make this service available constantly. Do I need to incorporate this in a jsp page which is externally accessible? `

leftist heap
Feb 28, 2013

Fun Shoe
Is it just for testing? Maybe run a local tomcat with it deployed, like this.

DholmbladRU
May 4, 2006

rrrrrrrrrrrt posted:

Is it just for testing? Maybe run a local tomcat with it deployed, like this.

Its a little more than testing. Currently I have apache tomcat running on a server. Can I deploy a eclipse Web Service project much like a war file on tomcat?

Sedro
Dec 31, 2008
The artifact of your build should be a war file.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

DholmbladRU posted:

Its a little more than testing. Currently I have apache tomcat running on a server. Can I deploy a eclipse Web Service project much like a war file on tomcat?

You should be able to export to a WAR file. Other options would be an ant build script or mavenize it

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


I've been tasked with a project to produce a report on methods nearing the 64k size limit. Our application uses a lot of jsps and generated code and we've seen issues in the past where a small change in one place leads to problems in other pages that import the new code. Does anyone have any idea how I could go about determining the size of a method compiled in a class file?

pigdog
Apr 23, 2004

by Smythe

HatfulOfHollow posted:

I've been tasked with a project to produce a report on methods nearing the 64k size limit. Our application uses a lot of jsps and generated code and we've seen issues in the past where a small change in one place leads to problems in other pages that import the new code. Does anyone have any idea how I could go about determining the size of a method compiled in a class file?

:stare: You are doing it wrong.

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


pigdog posted:

:stare: You are doing it wrong.

Ok, so maybe tell me the right way to do it? I'm not a java programmer at all. I'm a systems engineer and for some reason this task falls on us. And it is completely outside anything I would normally do.

pigdog
Apr 23, 2004

by Smythe
Sorry for the unhelpful post, I saw "64k methods" and kinda knee-jerked. If we're talking JSP's that are compiled into such monster methods, then that's another thing.

Try to have less crap stuff in your .jsp files, move the business logic to proper java classes, Javascript files to separate .js and such. While it's down to any particular JSP framework, perhaps try replacing static includes such as <%@ include file="blah.jsp" %> with dynamic like <jsp:include page="blah.jsp"/>. Anyhow, it depends a lot on your context. Could you decompile some of the .class files the JSP gets compiled into and see what takes up all the space?

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


pigdog posted:

Sorry for the unhelpful post, I saw "64k methods" and kinda knee-jerked. If we're talking JSP's that are compiled into such monster methods, then that's another thing.

Try to have less crap stuff in your .jsp files, move the business logic to proper java classes, Javascript files to separate .js and such. While it's down to any particular JSP framework, perhaps try replacing static includes such as <%@ include file="blah.jsp" %> with dynamic like <jsp:include page="blah.jsp"/>. Anyhow, it depends a lot on your context. Could you decompile some of the .class files the JSP gets compiled into and see what takes up all the space?

As I stated before, I'm on the engineering side of the house. The problem we have is that we have a lot of disparate teams working on different parts of the same application. Most of that work doesn't overlap, but occasionally someone will change a global file that gets included in many other places. Now it may work completely fine in their project, but it blows up something else. The development teams working on one project have no idea that their change is loving up 3 other teams. That's where I come in. As part of the Release Management team, we're responsible for any issues where integration issues occur. So, I've been tasked with coming up with a way to generate a report on method sizes that cross a threshold so we know the code needs to be more closely evaluated.

As far as your suggestions go, they make sense to me, but again, I can't enforce developer behavior changes. And even if we did, this could still happen due to various nested includes which could still gently caress up jspService (which is where 99% of these problems come from).

That said, I've been doing some research and it looks like some combination of org.apache.bcel.classfile.ClassParser, org.apache.bcel.classfile.Code, and org.apache.bcel.classfile.JavaClass should be enough to get me started.

Maybe I'll post my horrible code and you can all laugh at me.

leftist heap
Feb 28, 2013

Fun Shoe
We actually ran into this problem at my old job, but our solution was to just clean up the offending JSPs.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You do have automated tests, right? Just make it so people can't actually commit code to trunk unless those tests all pass.

That way if someone breaks another project, even if they don't find out about it while putting their commit together, they'll find out when they try to commit and can fix it before it ends up breaking that other team.

If your tests take too long to run to do them for every change, pick out a subset of them as quick "smoke tests" you can run for every commit, and save the rest for milestone builds or whatever.

DholmbladRU
May 4, 2006
ended up using different editor

DholmbladRU fucked around with this message at 15:15 on Aug 21, 2013

Volguus
Mar 3, 2009

HatfulOfHollow posted:

As I stated before, I'm on the engineering side of the house. The problem we have is that we have a lot of disparate teams working on different parts of the same application. Most of that work doesn't overlap, but occasionally someone will change a global file that gets included in many other places. Now it may work completely fine in their project, but it blows up something else. The development teams working on one project have no idea that their change is loving up 3 other teams. That's where I come in. As part of the Release Management team, we're responsible for any issues where integration issues occur. So, I've been tasked with coming up with a way to generate a report on method sizes that cross a threshold so we know the code needs to be more closely evaluated.

As far as your suggestions go, they make sense to me, but again, I can't enforce developer behavior changes. And even if we did, this could still happen due to various nested includes which could still gently caress up jspService (which is where 99% of these problems come from).

That said, I've been doing some research and it looks like some combination of org.apache.bcel.classfile.ClassParser, org.apache.bcel.classfile.Code, and org.apache.bcel.classfile.JavaClass should be enough to get me started.

Maybe I'll post my horrible code and you can all laugh at me.

When i had to inspect a lot of classes to make sure they behave (for other reasons than you), what I did was to write unit tests that would do the inspection for me. The tests would be run with each build, giving me very fast feedback on the status of the build.
The library i used was the ow2's asm library. They have apparently reached the 4.0 release but in maven they only have the 3.3.1 .
The maven dependency looks like this:
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

rhag posted:

When i had to inspect a lot of classes to make sure they behave (for other reasons than you), what I did was to write unit tests that would do the inspection for me. The tests would be run with each build, giving me very fast feedback on the status of the build.
The library i used was the ow2's asm library. They have apparently reached the 4.0 release but in maven they only have the 3.3.1 .
The maven dependency looks like this:
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>

Yeah I actually was playing around with exactly how to do this last night. I didn't see a mechanism to get just the byte code bytearray for a specific method.

I think the "easiest" way without trying to write some kind of huge java thing is to use javap to decompile each one of the stupid classes and see if there is a method with a byte position greater than (say) 62,000. Shouldn't be too hard to do with grep/awk.

HFX
Nov 29, 2004
I have to process a large number of text files that were originally written by some kind of Cobol program.

Many languages support the concept of writing into a record structure for output. The text files look like they were written by just such a program. Now, here comes the hard part. I would like to reverse this so my program can consume the document without me having to write a parser with lots of special rules. Are their any java libraries that given a record structure and format of items in it, they could automagically suck out the items into some Java objects?

Max Facetime
Apr 18, 2009

javassist is another Java bytecode library. Usually these libraries have two parallel APIs. A high-level API provides a view that looks similar to Java source code, but you'll want the low-level API which let's you see the bytes itself in bytecode.

Doctor w-rw-rw-
Jun 24, 2008

HFX posted:

I need to parse but I don't want to write a parser. Can I parse without creating a parser?

FTFY

You need a parser. Maybe a parser generator library will help but grammar description can still be pretty hard.

Off the top of my head - and this is super outdated - ANTLR is one such parser generator, though maybe something newer and shinier has come along since then.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

HFX posted:

I have to process a large number of text files that were originally written by some kind of Cobol program.

Many languages support the concept of writing into a record structure for output. The text files look like they were written by just such a program. Now, here comes the hard part. I would like to reverse this so my program can consume the document without me having to write a parser with lots of special rules. Are their any java libraries that given a record structure and format of items in it, they could automagically suck out the items into some Java objects?

Is this a COBOL master file or just a text output from some kind of log or extract? It may be possible to read in as byte delimited record fields. Do you have a few samples?

leftist heap
Feb 28, 2013

Fun Shoe

HFX posted:

I have to process a large number of text files that were originally written by some kind of Cobol program.

Many languages support the concept of writing into a record structure for output. The text files look like they were written by just such a program. Now, here comes the hard part. I would like to reverse this so my program can consume the document without me having to write a parser with lots of special rules. Are their any java libraries that given a record structure and format of items in it, they could automagically suck out the items into some Java objects?

If the format is just some arbitrary format, then I don't think so? If the syntax is really simple then I might just do it by hand. If it's more complex than, say, two terminals then I might use something like ANTLR.

HFX
Nov 29, 2004
Thanks guys. Looks like I'm going to be writing custom parsers and explaining why I can't just use regular expressions over and over. (Column + MultiLine + Context sensitivity ahoy!)

Adbot
ADBOT LOVES YOU

1337JiveTurkey
Feb 17, 2005

HFX posted:

Thanks guys. Looks like I'm going to be writing custom parsers and explaining why I can't just use regular expressions over and over. (Column + MultiLine + Context sensitivity ahoy!)

You might try flatworm although I haven't personally tried it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply