Captain Queenan is a good old boy from Southie who has grown up to be a captain in the Special Investigations Unit of the Massachusetts State Police. He's also something of a gentle father figure toward Billy Costigan—which means that he sometimes has to deliver some harsh truths to Billy. One of these harsh truths is the fact that Billy isn't a good fit for the force. As Queenan puts it:
QUEENAN: We deal in deception here. What we do not deal with is self-deception.
But Queenan is also smart enough to recognize that Billy could be very valuable to him as an undercover agent. So he uses Billy's background in Southie to make him a believable gangster. Even though he's fatherly, this dude is also resourceful and opportunistic.
The longer we watch Queenan, the more we learn about his personal connection to Frank Costello. He even calls Frank by the name Francis, which is what Frank's mother called him way back in the day. Queenan is also quick to add:
QUEENAN: And your father called you the tumor.
It's no stretch to say that Southie is a pretty small world, a place where all the cops and criminals grew up on the same playground and knew each other well. Just to show how personal the game between Queenan and Frank is, in fact, Queenan closes their conversation by saying:
QUEENAN: I'm gonna get you.
But Frank just laughs in his face and walks away like he probably did on the playground decades ago.
In the end, Queenan ends up giving his life to protect Billy. Of course, he doesn't know that he's going to die, but he at least has a good idea of the danger he's putting himself in. When the time comes to make a sacrifice, he tells Billy:
QUEENAN: I'II be fine. But if you get made I can't protect you. Now, go!
For his trouble, Queenan ends up getting thrown out a window and killed. But Queenan always knew there'd be risk involved in his cat-and-mouse game with Frank Costello, and it looks like he's paid the price for it.