I kind of have to agree with Sparks on seperating yourself from them both.
If David is so[sorry, but true] mentally unstable that he would kill himself if he didn't have you as a friend, he has serious issues he needs to work out with himself. He was about to shoot himself? Honestly? If that's not a red flag that he needs to be in a facility, I don't know what else is. If you really want to be his friend, you need to tell his parents AND a counselor at your school. Both. He needs help, more help than you think you can give him. I would be heart broken if I didn't have my friends, but to want to end my own life over it is just not normal or healthy. He needs to be more comfortable with himself than he is, and you just being his friend isn't going to help him short or long term.
As for your boyfriend, be prepared for this to happen as long as you're dating him. Really. If he is so potentially-violently jealous about someone you're just friends with and have been for a long time, your boyfriend has serious issues and this will be a problem of yours for, most likely, as long as you're dating. I would say "people can change" however, he knows it upsets you, I'm assuming you've asked him to stop, and you guys have already established you love eachother, and he has continued to be an idiot, that's more than likely not ever going to stop. He is obviously a really jealous person, and not to mention, a violent one. Sure, my boyfriend wasn't to pleased about me spending time with one of my best male friends, and it was hard for him at first, however there is a BIG difference between "I generally am uncomfortable with you being around thisperson" and "I want to kill your friend". Normally functional people don't do that. Maybe it is just because he's young or something, but I was 15 when I started dating and I've never come across anyone that.. crazy. I think you need to set your standards a little bit higher and aim for more normalcy, because that really isn't normal or healthy.
It really sounds like you are associating yourself with people that you should really be distancing yourself from. I hope you figure this out, but most importantly, make the best choices for your own well being, and Davids. Easier said than done, yes. But David will thank you one day, and you will thank yourself. Good luck, you're too young to be dealing with this kind of crap!